1. Match positive integer:/^[1-9]\D*$/2. Match nonnegative integer (positive integer +0):/^\d+$/3. Match Chinese:/^[\x{4e00}-\x{9fa5}]+$/u4. Match email:/^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) */5. URL of Match URL: ((((F|HT) {1} (TP|TPS)://) [[email protected]:%_\+.~#?&//=]+]6. Matches the beginning of the letter, 5-16 characters, Alphanumeric underline:/^[A-ZA-Z][A-ZA-Z0-9_]{4,15}$/7. Match numbers, letters, underscores, Chinese:/^[\x{4e00}-\x{9fa5}a-za-z0-9_]+$/u8. Matching China postcode: /^[1-9]\D{5}$/9. Matching IP address:/\b (?:(? : 25[0-5]|2[0-4][0-9]| [01]? [0-9] [0-9]?) \.) {3} (?: 25[0-5]|2[0-4][0-9]| [01]? [0-9] [0-9]?) \B/10. Match China Mainland ID:/^[1-9]\d{5}[1-9]\d{3} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) \d{3} (\d|x| X) $/php Regular Validation String Method Example:
<?PHPHeader("Content-type:text/html;charset=utf-8");$str= "Chinese ah";$preg= "/^[\x{4e00}-\x{9fa5}]+$/u";//Match Chineseif(Preg_match($preg,$str,$arr)){ $msg= ' Match succeeded! ‘;}Else{ $msg= ' Match failed! ‘;}Echo $msg;?>
JavaScript Common expression Usage
1. Matching positive integers:/^[0-9]*[1-9][0-9]*$/
2. Match non-negative integers (positive integer +0):/^\d+$/
3. Match Chinese:/^[\u4e00-\u9fa5]/
4. Match email:/^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) */
5. Match URL url:/^ (f|ht) {1} (TP|TPS): \/\/([\w-]+\.) +[\w-]+ (\/[\w-./?%&=]*)?
6. Match letter start, 5-16 characters, alphanumeric underline:/^[a-za-z][a-za-z0-9_]{4,15}$/
7. Match numbers, letters, underscores, Chinese:/^[\u4e00-\u9fa5a-za-z0-9_]+$/
8. Matching China postcode:/^[1-9]\d{5}$/
9. Match IP address:/\b (?:(? : 25[0-5]|2[0-4][0-9]| [01]? [0-9] [0-9]?) \.) {3} (?: 25[0-5]|2[0-4][0-9]| [01]? [0-9] [0-9]?) \b/
10. Match the Chinese mainland identity card:/^[1-9]\d{5}[1-9]\d{3} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) \d{3} (\d|x| X) $/
Examples of JavaScript Regular validation string methods:
<script type= "Text/javascript" >var str = "[email protected]"; var preg =/^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) */; if (Preg.test (str)) {var msg = ' Match succeeded! ';} Else {var msg = ' match failed! ';} Alert (msg); </script>
Regular expressions commonly used in web development