PHP Common Regular expression function we have a lot of normal expression code here, including the judgment Zhong Wenjing, the number of letters, the word regular is the expression test, the number of regular expression test, the mailbox regular expression, the phone number is the expression test, mobile phone number is the expression test, zip code regular expression test,/url regular expression test, etc. oh.
Common regular expression functions for PHP tutorials
We have a lot of face in the expression code, including the Judgment Zhong Wenjing, the number of letters regular, the word regular expression test, the number of regular expression test, the mailbox regular expression, the phone number is the expression test, mobile phone number is the expression test, zip code is the expression test,/url regular expression test, etc. oh.
*/
function Funcchinese ($str, $num 1= ", $num 2 =")//Judge Zhong Wenjing
{
if ($num 1!= "and $num 2!=") {
Return (Preg_match ("/^ ([X81-xfe][x40-xfe]) {". $num 1. ",". $num 2. "} $/", $str))? True:false;
}else{
Return (!eregi ("[^x80-xff]", "$str"))? True:false;
}
}
function Funcstrnum ($str, $num 1= ", $num 2 =")//digital Letter Regular
{
if ($num 1!= "and $num 2!=") {
Return (Preg_match ("/^[^0-9a-za-z_@!"). -]{". $num 1.,". $num 2. "} $/", $str))? True:false;
}else{
Return (Preg_match ("/^[^0-9a-za-z_@!"). -]/", $str))? True:false;
}
}
Common Regular Expression test
function Funcstr ($str, $num 1= ", $num 2 =")//Word Regular
{
if ($num 1!= "and $num 2!=") {
Return (Preg_match ("/^[a-za-z]{". $num 1. ",". $num 2. "} $/", $str))? True:false;
}else{
Return (Preg_match ("/^[a-za-z]/", $str)) True:false;
}
}
function Funcnum ($str, $num 1= ", $num 2 =")//digital Regular expression test
{
if ($num 1!= "and $num 2!=") {
Return (Preg_match ("/^[0-9]{". $num 1. ",". $num 2. "} $/", $str))? True:false;
}else{
Return (Preg_match ("/^[0-9]/", $str)) True:false;
}
}
function Funccard ($STR)//
{
Return (Preg_match ('/(^ [d]{15}|[ d]{18}| [d] {17}x) $)/', $str))? True:false;
}
function Funcemail ($STR)//mailbox Regular expression
{
Return (Preg_match ('/^[_.0-9a-z-a-z-]+@ ([0-9a-z][0-9a-z-]+.) +[a-z]{2,4}$/', $str))? True:false;
}
function Funcphone ($STR)//telephone number regular expression test
{
Return (Preg_match ("/^ ((D{3}) | ( d{3}-))? ((0d{2,3}) |0d{2,3}-)? [1-9]d{6,8}$/", $str))? True:false;
}
function Funcmtel ($STR)//Mobile phone number regular expression test
{
Return (Preg_match ("/(?: 13d{1}|15[03689]) d{8}$/", $str))? True:false;
}
function Funczip ($STR)//Postcode regular expression test
{
Return (Preg_match ("/^[0-9]d{5}$/", $str)) True:false;
}
function Funcurl ($STR)//url Regular expression test
{
Return (Preg_match ("/^http://[a-za-z0-9]+.[ a-za-z0-9]+[/=?%-&_~ ' @[] ': +!] * ([^<> ""]) *$/", $str))? True:false;
}
http://www.bkjia.com/PHPjc/444901.html www.bkjia.com true http://www.bkjia.com/PHPjc/444901.html techarticle common Regular expression functions in PHP we have a lot of expressions in the expression code, including the Judgment Zhong Wenjing, the number letter regular, the word regular is the expression test, the number regular expression test, the mailbox regular table ...