1, identity card number (15/18 bit)
Introduction
xxxxxx yyyy MM dd 375 0 eighteen
xxxxxx yy MM dd 75 0 fifteen
area:
[1-9]\d{5}
The first two years:
(18|19|([23]\d))
1800-2399After two years:
\d{2}
month:
((0[1-9])|(10|11|12))
Days:
(([0-2][1-9])|10|20|30|31)
leap year can not prohibit 29+Three order code:
\d{3}
Two order code:
\d{2}
Checksum:
[0-9Xx]
Regular Expressions
Eighteen:
^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$
Fifteen:
^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$
total:
(
^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$
)
First, the check digit of expression
1. Digital: ^ [0-9] * $
2. n-bit numbers: ^ d {n} $
3. The bit number n at least: ^ d {n,} $
Digital 4. mn bits: ^ d {m, n} $
The digital zero and non-zero at the beginning: ^ (0 | [1-9] [0-9] *) $
6. With the beginning of zero up to two decimal places: ^ ([1-9] [0-9] *) $ + ([0-9] {1,2})?
7. 1-2 with decimals, positive or negative: ^ (-) d + (d {1,2}.) $??
8. positive, negative, and decimals:?? ^ (- | +) d + (. D +) $
9. Two positive real number of decimal places: (. [0-9] {2})? ^ [0-9] + $
1 to 10. The three positive real number of decimal places: (. [0-9] {1,3})? ^ [0-9] + $
11. The non-zero positive integer: ^ [1-9] * $ or D ^ ([1-9] [0-9] *), or {1,3} ^ $ + [1-9] [0-? 9] * $
12. The non-zero negative integer: ^ - [1-9] [] 0-9 "or * ^ $ - [1-9] * $ D
13. A non-negative integers: ^ d + $ or ^ [1-9] d * | 0 $
14. Non-positive integer: ^ - [1-9] d * | 0 $ or ^ ((- d +) | (0 +)) $
15. A non-negative floating-point numbers: ^ d + (d +.) $ Or ^ [1-9] d * .d * | 0.d * [1-9] d * | 0 .0+ | 0 $??
16. Non-positive float: (.?.? (- d + (d +)) | (0 + (0 +))) ^ $ or ^ (- ([1-9] d * .d * | 0.d * [1-9] d *)) | 0 .0+ |? 0 $
17. The positive float: ^ [1-9] d * .d * | 0.d * [1-9] d * $ ^ or (([0-9] + [0-9] * [1. 9] [0-9] *) | ([0-9] * [1-9] [0-9] * [0-9] +) |. ([0-9] * [1-9] [ 0-9] *)) $
18. The negative float: ^ - ([1-9] d * .d * | 0.d * [1-9] d *) $ or ^ (- (([0-9] + [0-9. ] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * [0-9] +) |. ([0-9] * [ 1-9] [0-9] *))) $
19. Float: ^ (- d +?) $ Or ^ - ([1-9] d * .d * | 0.d * [1-9] d * | 0 .0+ (d +.)??? | 0) $
Second, check character expression
1. Characters: ^ [u4e00-u9fa5] {0,} $
2. alphanumeric: ^ [A-Za-z0-9] + $ or ^ [A-Za-z0-9] {4,40} $
3. The length of all characters 3-20: {^} $ 3,20.
4. The string consists of the 26 English letters: ^ [A-Za-z] + $
The string consists of 26 English capital letters: ^ [AZ] + $
6. The letters written by a small string consisting of 26: ^ [az] + $
7 and 26 by the numeral string of English letters: ^ [A-Za-z0-9] + $
8. The string of numbers, letters or underscore 26 consisting of: ^ w + $ or ^ w {3,20} $
9. Chinese, English, numbers underlined comprising: ^ [u4E00-u9FA5A-Za-z0-9 _] + $
10. Chinese, English, numbers, symbols such as but not underlined: ^ [u4E00-u9FA5A-Za-z0-9] + $ or ^ [u4E00-u9FA5A-Za-z0-9] {2,20} $
11. The input may contain% ^ & '?,; = $ "Characters such as: [^% &',; = $ x22?] + 12 ~ disable input characters comprising: [^ ~ x22] +
Third, the special needs of expression
1. Email地址:^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$
2. 域名: [a-zA-Z0-9] [- a-zA-Z0-9] {0,62} (/. [A-zA-Z0-9] [- a-zA-Z0-9] {0,62}) + /.
3. InternetURL:[a-zA-z]+://[^s]* 或 ^http://([w-]+.)+[w-]+(/[w-./?%&=]*)?$
4. phone number: ^ (13 [0-9] | 14 [5 | 7] | 15 [0 | 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9] | 18 [0 | 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9]) d {8} $
The phone number ( "XXX-XXXXXXX", "XXXX-XXXXXXXX", "XXX-XXXXXXX", "XXX-XXXXXXXX", "XXXXXXX" and "XXXXXXXX): ^ ((d {3,4} -) | d {3.4} -?) d {7,8} $
6. domestic telephone number (0511-4405222,021-87888822): d {3} -d {8} | d {4} -d {7}
ID No. 7. (15, 18 digit): ^ d {15} | d {18} $
8. Short ID number (number, letter x end):? ^ ([0-9]) {7,18} (x | X) $ or ^ d {8,18} | [0-9x] {8 , 18} | [0-9X] {8,18} $?
9. The account is valid (beginning with the letter, allowing 5-16 bytes to allow alphanumeric underlined): ^ [a-zA-Z] [a-zA-Z0-9 _] {4,15} $
10. Password (start with a letter, a length between 6 and 18, can contain letters, numbers and underscores): ^ [a-zA-Z] w {5,17} $
11. A strong password (must contain a combination of uppercase and lowercase letters and numbers, special characters can not be used, a length of between 8-10): (?. = * [Az])? ^ (?. = * D) (=. * [AZ]). {8,10} $
12. Date format: ^ d {4} -d {1,2} -d {1,2}
13. The year 12 months (01 ~ 09 and 1 ~ 12): ^ (0 [1-9] | 1 [0-2]?) $
14 month 31 days (01 ~ 09 and 1 ~ 31): ^ ((0 [1-9]) | ((1 | 2) [0-9]) | 30 | 31?) $
15. The money input formats:
16. 1. There are four representations of money we can accept: "10000.00" and "10,000.00" and not "divide" and "10000" and "10,000": ^ [1-9] [0-9] * $
17. 2. This does not represent any of a number from 0 to begin with, but it also means that a character "0" is not passed, so we take the following form: ^ (0 | [1-9] [0-9] *) $
18. 3. a 0 or a number from 0 to not begin with we can also allow the beginning there is a minus: ^ (0 | - [1-9] [0-9] *?) $
19. 4. This may represent a 0 or a negative number 0 is not the beginning of the let users start with 0 as well. The minus sign also removed, because the money can not be negative right. Now we want to add the It is a possible fractional part: ^ [0-9] + (. [0-9] +) $?
20. 5. It must be noted that, after the decimal point should be at least 1 digit, so "10" is not adopted, but "10" and "10.2" are adopted: ^ [0-9] + ([. 0-9] {2})? $
21. 6. The provisions of this we must have two after the decimal point, if you think too hard, it can be: (. [0-9] {1,2})? ^ [0-9] + $
7. 22. This allows a user to write only a decimal number following the comma we considered, we can:. ^ [0-9] {1,3} (, [0-9] {3}) * (. [0-9] {1,2})? $
23 8.1 to 3 digits, followed by comma +3 arbitrary numbers, commas become optional, rather than necessary: ^ ([0-9] + | [0-9] {1,3} (, [0- 9] {3}) *) (. [0-9] {1,2})? $
24. Note: This is the final result, do not forget the "+" can use the "*" alternative if you feel empty string can accept it (wonder why?) Finally, do not forget that when using the function remove remove backslash, general errors are here
25. XML 文件: ^ ([a-answer-Z] + -?) + [A-answer-Z0-9] +. [X | X] [|] [l | L] $
26. Chinese characters in regular expressions: [u4e00-u9fa5]
27. A double-byte characters: [^ x00-xff] (including characters included, the length may be used (a double-byte character string length counter 2 is calculated, the ASCII characters are counted 1))
28. The positive expression blank line: ns * r (can be used to delete blank lines)
29. HTML tag regex: <(S *?) [^>] *> * </ 1> | <* /> (circulated on the Internet version too bad, above this was only partially.?.? for complex nested tags still do nothing)
30. Positive and last blank character expression: ^ s * | s * $ or (^ s *) | (s * $) (can be used to delete the row end of the first line blank characters (including spaces, tabs, page breaks, etc.), very useful expression)
31. Tencent QQ: [1-9] [0-9] {4,} (Tencent QQ number 10000 from the start)
32. China Postal Code: [1-9] d {5} (?! d) (6-digit ZIP code for China)
33. A IP address: d + .d + .d + .d + (useful for the extraction of the IP address)
34. IP Address: (? (:( ?: 25 [0-5] | 2 [0-4] d | [01] d d)??.) {3} (?: 25 [0-5] | 2 [0-4] d | [01] d d))??