HTML5- common regular expressions

First, the check digit of expression

 

1. Digital: ^ [0-9] * $

2. n-bit numbers: ^ \ d {n} $

3. at least n bit digital: ^ \ 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] \ d * $ or ^ ([1-9] [0-9] *) or $ {1,3} ^ \ + [1-9] [? 0-9] * $

12. The negative integer zero: ^ \ - [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 +) (. \ \ D +) $ or ^ - ([1-9] \ d * \ \ d * | 0 \ \ d * [1-9] \ d * | 0 \ 0+ |?. 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 digits, letters or underscore 26 consisting of: ^ \ w + $ or ^ \ w {3,20} $

9. Chinese, English, numbers, including underscore: ^ [\ 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. Prohibition of input character contained ~: [^ ~ \ 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} $

5. 电话号码("XXX-XXXXXXX"、"XXXX-XXXXXXXX"、"XXX-XXXXXXX"、"XXX-XXXXXXXX"、"XXXXXXX"和"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}

7. ID NO:
    15 or ID 18: ^ \ d {15} | \ d {18} $

    ID 15: ^ [1-9] \ d {7} ((0 \ d) | (1 [0-2])) (([0 | 1 | 2] \ d) | 3 [0-1 ]) \ d {3} $

    ID 18: ^ [1-9] \ d {5} [1-9] \ d {3} ((0 \ d) | (1 [0-2])) (([0 | 1 | 2 ] \ d) | 3 [0-1]) \ d {4} $

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): ^ (?. = * \ D) (= (= * [az]?.)? . * [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 format:
16. 1. There are four forms of representation 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 Bunken: (? [A-zA-Z] + -). ^ + [A-zA-Z0-9] + \\ [x | X] [m | M] [l | L] $

Positive 26. Chinese characters expression: [\ u4e00- \ u9fa5]

27. A double-byte characters: [^ \ x00- \ xff] (including characters included, can be used to calculate the length of the string (a double-byte character length meter 2, ASCII characters are counted 1))

28. The positive expression blank line: \ n \ s * \ r (can be used to delete blank lines)

29. HTML tag regex: <(\ S *?) [^>] *> * </ \ 1> | <* /> (circulated on the Internet version too bad, was only able to top this.?.? part, for the complex nested tags still do nothing)

30. The positive end to end whitespace regular expression: ^ \ s * | \ s * $ or (^ \ s *) | (\ s * $) (can be used to delete the row end of the first line blank characters (including spaces, system table breaks, 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: (?! \ D) [1-9] \ d {5} (ZIP code for China 6 digits)
 
33. A IP address: \ d + \ \ d + \ \ d + \ \ d + (useful for the extraction of the IP address)...

Guess you like

Origin www.cnblogs.com/btsn/p/10986438.html