Home >Backend Development >PHP Tutorial >Commonly used regular expression functions in php_PHP tutorial

Commonly used regular expression functions in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:08:11957browse

Commonly used regular expression functions in PHP. We have many regular expression codes here, including judging Chinese regular expressions, digital and alphabetic regular expressions, character regular expressions, digital regular expressions, email regular expressions, phone number regular expressions, and mobile phone number regular expressions. Expression test, zip code regular expression test, /url regular expression test, etc.

Commonly used regular expression functions in PHP tutorials
We have a lot of regular expression codes here, including judging Chinese regular expressions, digital and alphabetical regular expressions, character regular expression tests, digital regular expression tests, email regular expressions, and phone numbers Regular expression test, mobile phone number regular expression test, zip code regular expression test, /url regular expression test, etc.
*/
function funcchinese($str,$num1='',$num2='')//Judge Chinese regular rules
{
if($num1!='' and $num2! =''){
return (preg_match("/^([x81-xfe][x40-xfe]){".$num1.",".$num2."}$/",$str)) ?true:false;
}else{
return (!eregi("[^x80-xff]","$str"))?true:false;
}
}

function funcstrnum($str,$num1='',$num2='') //Numbers and letters are regular
{
if($num1!='' and $num2!=''){
return (preg_match("/^[^0-9a-za-z_@!.-]{".$num1.",".$num2."}$/",$str))?true: false;
}else{
return (preg_match("/^[^0-9a-za-z_@!.-]/",$str))?true:false;
}
}
//Commonly used regular expressions

function funcstr($str,$num1='',$num2='') //Character regular expressions
{
if ($num1!='' and $num2!=''){
return (preg_match("/^[a-za-z]{".$num1.",".$num2."}$/ ",$str))?true:false;
}else{
return (preg_match("/^[a-za-z]/",$str))?true:false;
}
}

function funcnum($str,$num1='',$num2='')//Number regular expression try
{
if($num1!='' and $num2!=''){
return (preg_match("/^[0-9]{".$num1.",".$num2."}$/",$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 try
{
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 try
{
return (preg_match("/(?:13d{1}|15[03689])d{8}$ /",$str))?true:false;
}

function funczip($str)//Postal code regular expression try
{
return (preg_match("/^[0 -9]d{5}$/",$str))?true:false;
}

function funcurl($str)//url regular expression try
{
return (preg_match("/^http://[a-za-z0-9]+.[a-za-z0-9]+[/=?%-&_~`@[]':+!]*( [^<>""])*$/",$str))?true:false;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444901.htmlTechArticlephp Common Regular Expression Functions We have a lot of regular expression codes here, including judging Chinese regular expressions, numbers and letters Regular expression, character regular expression test, digital regular expression test, email regular table...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn