Regular symbols:
* match the previous character 0 or more times.
^ matches the beginning of the line ^hello : Matches the character starting with Hello.
$ Match line not hello$ : matches the character ending with Hello.
. Matches any one character that is considered to be in addition to a line break.
[] matches any one of the characters in the parentheses [ABCD]: matches any one of the ABCD characters.
[^] Match removes any one of the characters in parentheses [^0-9] : matches any non-numeric character.
\{n\} indicates that the preceding characters appear exactly n times. [0-9]\{4\} : matches 4 digits.
\{n,\} indicates that the preceding character is not less than n times [0-9]\{\4,\}: Matches 4-bit and 4-bit characters.
\{n,m\} [0-9]\{n,m\}
JS's:/** [REGEXPSTR Check if string is specified format] * @param {string} string [to be detected] * @param {type} type [detection type] * @return {Boolean} */functionregexpstr (string, type) {if(!type)varType = ' pwd '; if(!in_array (type, [' Integer ', ' Nninteger ', ' zh-cn ', ' email ', ' url ', ' pwd ', ' post-code ', ' zh-en ', ' IP ', ' id-number ', ' Mobil E])) return false; if($.trim (string) = = ") return false; varRegExp = { //match positive integers' Integer ':/^[1-9]*[1-9][0-9]*$/, //match non-negative integers (positive integers +0)' Nninteger ':/^\d+$/, //Match Chinese' ZH-CN ':/^[\u4e00-\u9fa5]{2,4}$/, //Match Email//' Email ':/^ ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9][email protected] ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9]+\. [A-za-z] {2,3}$/, //Match URL URLs' URL ':/^ (F|HT) {1} (TP|TPS): \/\/([\w-]+\.) +[\w-]+ (\/[\w-./?%&=]*)?/,//Match letter Start, 5-16 characters, alphanumeric underline' pwd ':/^[a-za-z][a-za-z0-9_]{5,15}$/, //Match China postcode' Post-code ':/^[1-9]\d{5}$/, //match numbers, letters, underscores, Chinese' Zh-en ':/^[\u4e00-\u9fa5a-za-z0-9_]+$/, //Match IP Address' IP ':/\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/, //match Chinese mainland identity card' Id-number ':/^[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) $/, //match Mainland mobile phone number' Mobile ':/(13[0-9]|14[0-9]|15[0-9]|18[0-9]|17[0-9]) [0-9]{8}$/ }; returnEval (Regexp[type]). Test (String)?true:false;}if(!function_exists ("Regexpstr")) { /** Common Regular*/ functionRegexpstr ($string =NULL, $type = ' pwd ') { if(Empty ($string))return false; $regexp=Array (//match positive integers' Integer ' = '/^[1-9]\d*$/', //match non-negative integers (positive integers +0)' Nninteger ' = '/^\d+$/', //Match Chinese' ZH-CN ' = '/^[\x{4e00}-\x{9fa5}]+$/u ', //Match Email///^[0-9a-za-z]+ (?: [\_\.\-][a-z0-9\-]+) *@[a-za-z0-9]+ (?: [-.] [a-za-z0-9]+] *\. [A-za-z]+$/i ///^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) * /' Email ' = '/^\w+ ' ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) */', //Match URL URLs' url ' = '/^ ' (http:\/\/)? (https:\/\/)? ([\w\d-]+\.) +[\w-]+ (\/[\d\w-.\/?%&=]*)? $/', //Match letter Start, 5-16 characters, alphanumeric underline' pwd ' = '/^[a-za-z][a-za-z0-9_]{5,15}$/', //Match China postcode' Post-code ' = '/^[1-9]\d{5}$/', //match numbers, letters, underscores, Chinese' Zh-en ' = '/^[\x{4e00}-\x{9fa5}a-za-z0-9_]+$/u ', //Match IP Address' IP ' = '/\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/', //match Chinese mainland identity card' Id-number ' = '/^[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) $/', //match Mainland mobile phone number//' mobile ' = '/^ (?: 13\d{9}|15[0|1|2|3|5|6|7|8| 9]\d{8}|18[0|2|3|5|6|7|8| 9]\D{8}|14[5|7]\D{8}) $/',' Mobile ' = '/(13[0-9]|14[0-9]|15[0-9]|18[0-9]|17[0-9]) [0-9]{8}$/', ' Ymdhis ' = '/^\d{4}[\-] (0?[ 1-9]|1[012]) [\-] (0?[ 1-9]| [12] [0-9]|3[01]) (\s+ (0?[ 0-9]|1[0-9]|2[0-3]) \:(0? [0-9]| [1-5] [0-9]) \:(0? [0-9]| [1-5] [0-9])? $/', ' Ymd ' = '/^d{4}-d{2}-d{2} ', ); if(Empty ($regexp [$type]))returnFALSE; Preg_match ($regexp [$type], $string, $res); return$res?True:false; }}
The basic regular