PHP Common validation Regular expression, PHP regular expression _php tutorial

Source: Internet
Author: User
Tags ereg php regular expression

PHP Common validation Regular expression, PHP regular expression


Number, mobile phone number, QQ number, URL address legality check

1. Verify that it is an integer

1 function isnumber ($val)2    {3             if(ereg  $val))4                 returntrue; 5             return false ; 6      }

2. Verify that the phone number is

1 function isphone ($val) {2             3           if (ereg("^1[ 1-9][0-9]{9}$ ",$val))4           returntrue; 5         return false ; 6     7           8     }

3. Verify that the QQ number is valid

1 function isqq ($val) {2             3           if (  Ereg("^[1-9][0-9]{4,12}$",$val))4           returntrue ; 5         return false ; 6     7           8     }

4. Verify that the URL address is legitimate

1 functionIsurl ($s)  {  2         return Preg_match('/^http[s]?:\ /\/'.3' (([0-9]{1,3}\.) {3} [0-9] {1,3} './/URL-199.194.52.184 in IP form4'|'.//Allow IP and domain (domain name)5' ([0-9a-z_!~*\ ' ()-]+\.) *'.//domain name-www. 6' ([0-9a-z][0-9a-z-]{0,61})? [0-9a-z]\.]//level two domain name7' [a-z]{2,6}] './/First level domain-. com or. Museum8' (: [0-9]{1,4})? './/Port-:9'((\/\?)|'.//a slash isn ' t required if there is no file nameTen' (\/[0-9a-za-z_!~\ ' \ (\) \[\]\.;\?:@&=\+\$,%#-\/^\*\|] *)?) $/', One             $s) = = 1;  A}

It is easy to use, such as verifying that the phone number is valid:

$val= ' 15093691582 '; Isphone ($val);

http://www.bkjia.com/PHPjc/1048725.html www.bkjia.com true http://www.bkjia.com/PHPjc/1048725.html techarticle PHP Common validation Regular expression, PHP regular expression number, mobile phone number, QQ number, URL address legality check 1. Verify that the integer 1 function isnumber ($val) 2 {3 if (Ereg ("^[0-...

  • Related Article

    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.