An expression for a checksum number

The Numbers: ^ [0-9] * $n bit Numbers: ^ \ d {n} $at least n bit Numbers: ^ \ d {n,} $m - n bit Numbers: ^ \ d {m, n} $the number of zero and non-zero start: ^ (0| [1-9] [0-9]*)$Non-zero digits with at most two decimal places: ^([1-9] [0-9] *) + (. \ [0-9] {1.2})? $with1-2Decimal positives or negatives: ^(\-)? \d+(\.\d{1.2}) $positive, negative, and decimal: ^ (\ | \ +)? \d+(\.\d+)? $a positive real number with two decimal places: ^[0-9] + (\ [0-9] {2})? $a1~3Positive real numbers of decimal places: ^[0-9] + (\ [0-9] {1.3})? $non-zero positive integer: ^[1-9] \ d * $or ^ ([1-9] [0-9] *) {1.3} $or ^ \ +? [1-9] [0-9]*$non-zero negative integer: ^\-[1-9] []0-9"* $or ^ - [1-9] \ d * $nonnegative integers: + $or ^ ^ \ d \ d * (1-9] | 0 $a positive integer: ^ - [1-9] \ d * | 0 $or ^ ((\ d +) | (0 +)) $nonnegative floating-point number: ^ \ d + (. \ \ d +)? $or ^ [1-9] \ d * \ \ d * \ | 0. [1-9] \ d \ d * * | 0? \. | 0 0 + $is a floating point number: ^ ((\ d + (. \ \ d +)?) | (0 + (\. 0 +)? ) $or ^ (- (1-9] [\ d * \ \ d * \ | 0. [1-9] \ d \ d * *)) | 0? \. | 0 0 + $are floating point Numbers: ^ 1 - [9] \ d * \ \ d * \ | 0. 1-9] [\ \ d * d * $or ^ (([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \ [0-9] +) | ([0-9] * [1-9] [0-9] *)) $negative floating point Numbers: ^ - (1-9] [\ d * \ \ d * \ | 0. 1-9] [\ \ d * d *) $or ^ (- (([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \ [0-9] +) | ([0-9] * [1-9] [0-9] *))) $ Floating point: ^(-? \d+)(\.\d+)? $or ^ -? ([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0? $\. | 0 + 0)Copy the code

An expression to validate a character

Chinese characters: ^ [\ u4e00 - \ u9fa5] {0}$English and numerals: ^[a-za-z0 -9[A] + $or ^ - Za - z0 -9] {4.40} $for length3-20All characters of: ^.{3.20} $by26The value is A string of letters: ^[a-za-z]+$26The value is A string of uppercase letters: ^[a-z]+$26It is a string of lowercase letters: ^[a-z]+$and digits26The value is A string of letters: ^[a-za-z0 -9]+$By number,26A string of letters or underscores: ^\w+$or ^\w{3.20}$Chinese, English and digits including underscores: ^[u4E00-\ U9FA5A-za-z0-9_]+$Chinese, English and digits but not including underscores: ^[u4E00-\ U9FA5A-za-z0 -9[\ u4E00 - \] + $or ^ u9FA5A - Za - z0 -9] {2.20}$can be entered containing ^%&',; =? $\" and other characters: [^%&',; =? $\x22]+ Do not enter characters containing ~ : [^~\x22]+Copy the code

Special requirement expression

Email address: ^ \ w + (\ w + / - +.]) * @ \ w + ([-] \ w +) * \ \ w + ([-] \ w +) * $domain: [a - zA - Z0 -9][-a-zA-Z0-9] {0.62}(\.[a-zA-Z0-9][-a-zA-Z0-9] {0.62}) + \.? InternetURL: [a zA - z] + :/ / [^ \ s] * or ^ http:// ([-] \ w + \.) +[\w-]+(/[\w-./?%&=]*)? $Mobile phone Number: ^(13[0-9] |14[5|7] |15[0|1|2|3|4|5|6|7|8|9] |18[0|1|2|3|5|6|7|8|9])\d{8$Telephone No. ("XXX-XXXXXXX","XXXX-XXXXXXXX","XXX-XXXXXXX","XXX-XXXXXXXX","XXXXXXX"and"XXXXXXXX) : ^ (\ (\ d {3, 4} -) | \ d {} 3.4 -)? \ d {7, 8} $home phone number (0511-4405222, 021-87888822) : \ d {3} - \ d {8} | \ d {4} - \ d {7} phone number a regular expression (support mobile phone number, the code for 3-4, 7-8 live number, 1-4 extension) : ((\ d {11}) | ^ ((\ d {7, 8}) | (\ d {4} | \ d {3}) - (\ d {7, 8}) | (\ d {4} | \ d {3}) - (\ d {7, 8}) - (\ d {4} | \ d {3} | \ d {2} | \ d {1}) | (\ d {7, 8}) - (\ d {4} | \ d {3} | \ D {2} | \ d {1})) $) identification number (15, 18, and digital), and the last is the check digit, may for digital or character X: 15 (^ \ d {} $) | | (^ \ d {and} $) (^ \ d {and} (\ d | | X) X $) account is legal (letter, allow 5-16 bytes, allow alphanumeric underscore) : ^[a-za-z][a-za-z0-9_]{4,15}$the password must start with a letter and contain 6 to 18 letters, digits, and underscores (_) only. ^[a-za-z]\w{5,17}$strong password (must contain uppercase and lowercase letters and digits, cannot use special characters, between 8 and 10 characters in length) : ^(? =.*\d)(? =.*[a-z])(? =. * [a-z]) [A zA - Z0-9] {8, 10} $strong password (must include the case the combination of letters and Numbers, you can use special characters, length between 8 to 10) : ^ (? =.*\d)(? =.*[a-z])(? =. * [a-z]). 8, 10 {} $date format: ^ \ d {4} \ d {1, 2} - \ d {1, 2} 12 months of the year (01 ~ 09 and 1 ~ 12) : ^ (0? [1-9] | 1 [2-0]) $a month of 31 days (01 ~ 09 and 1 ~ 31) : ^ ((0? [1-9]) | | 2 (1) ([0-9]) | | 30 31) $money input formats: there are four kind of money we can accept representation:"10000.00" 和 "10.00000.", and nothing"points" 的 "10000" 和 "10.000": ^[1-9][0-9]*$This means any number that does not start with 0, but this also means a character."0"Not through, so we use the form below: ^ (0 | [1-9] [0-9] *) $a 0 or a digital does not begin with 0. We can also allow the beginning there is a minus sign: ^ (0 | -? [1-9][0-9]*)$This represents a 0 or a potentially negative number that does not begin with a 0. Let the user start with 0. Let's get rid of the minus, because money can't be negative. ^[0-9]+(.[0-9]+)? The $has to be at least 1 digit after the decimal point, so"10."It doesn't pass, but."10" 和 "10.2"Is passed: ^[0-9]+(.[0-9]{2})? $so we must have two decimal point behind, if you think that is too harsh, it can be: ^ [0-9] + (. [0-9] {1, 2})? This allows the user to write only one decimal digit. Below we should consider a comma in the digital, we can be like this: ^ [0-9] {1, 3} ([0-9] {3}), * (. [0-9] {1, 2})? The $1 to 3 number, followed by any comma + 3 Numbers, comma become optional, rather than having to: ^ ([0-9] + | [0-9] {1, 3} ([0-9] {3}), *) (. [0-9] {1, 2})? $note: This is the final result, don't forget"+"Can be used."*"Instead if you think empty strings are acceptable (strange, why?) Finally, don't forget to get rid of the backslash when you use the function. The usual error is in the XML file: ^([a-za-z]+-?) + [a zA - Z0-9] + \ \ | x [x] [m | m] [l] | l $Chinese characters of regular expressions: [\ u4e00 - \ u9fa5] double-byte characters: [^\x00-\ XFF] (including Chinese characters, which can be used to calculate the length of a string (a two-byte character is 2, ASCII 1)) regular expression for blank lines: \n\ S* \r (which can be used to delete blank lines) Regular expression for HTML tags: <(\ s*?) [^ >] * >. *? | <. *? / > (fore and aft blank characters of regular expressions: ^ | \ \ s * s * $or (^ \ s *) | (\ s * $) (can be used to delete rows first line of white space characters (including Spaces, tabs, form-feed character, etc.), very useful expressions) tencent QQ number: [1-9] [0-9] {4} (tencent QQ number since 10000) China zip code: [1-9] \ d {5} (? ! \ d) (China postal code is 6 digits) IPv4 address: ((2 (5 [0 to 5] | \ [0-4] d)) | [0, 1]? (\ \ d {1, 2}). ((2 (5 [0 to 5] | \ [0-4] d)) | [0, 1]? \ d {1, 2} {3}))Copy the code

This article is reprinted from: c.runoob.com/front-end/8…