Regular expression for PHP verification-php Tutorial

Source: Internet
Author: User
PHP commonly used to verify the validity of regular expression numbers, mobile phone numbers, QQ numbers, and URLs 1. verify that it is an integer of 1 functionisNumber ($ val) 2 {3if (ereg (^ [0-9] + $, $ val) 4 returntrue; 5 returnfalse; 6 PHP regular expression

Validity verification of numbers, mobile phone numbers, QQ numbers, and Url addresses

1. verify whether it is an integer

1 function isNumber($val)2     {3             if(ereg("^[0-9]+$", $val))4                 return true;5             return false;6      }

2. verify whether the mobile phone number is used

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

3. verify if it is a valid QQ number

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

4. verify whether the Url address is valid

1 function isUrl ($ s) {2 return preg_match ('/^ http [s]? :\/\/'. 3' ([0-9] {1, 3 }\.) {3} [0-9] {1, 3 }'. // URL in IP format-199.194.52.184 4 '| '. // allow IP address and DOMAIN (DOMAIN name) 5' ([0-9a-z _! ~ * \ '()-] + \.) *'. // Domain name-www. 6' ([0-9a-z] [0-9a-z-] {0, 61 })? [0-9a-z] \. '. // second-level domain 7' [a-z] {2, 6 })'. // first level domain -. com or. museum 8' (: [0-9] {1, 4 })? '. // Port-: 80 9 '((\/\?) | '. // A slash isn' t required if there is no file name 10' (\/[0-9a-zA-Z _!~ \ '\ (\) \ [\] \.; \? : @ & =\+ \ $, % #-\/^ \ * \ |] *)? $/', 11 $ s) = 1; 12}

The usage is simple, such as verifying whether the mobile phone number is valid:

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

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.