PHP Common Regular expression Function _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.