Only one number can be entered
Expression ^ \ D $
The description matches a number.
Matching example 0, 1, 2, 3
Example of Mismatch
Only n numbers can be entered
Expression ^ \ D {n} $ for example ^ \ D {8} $
The description matches 8 numbers.
Matching example: 12345678,22223334, 12344321
Example of Mismatch
You can enter at least N numbers.
Expression ^ \ D {n ,}$ for example ^ \ D {8,} $
The description matches at least N numbers.
Matching example: 12345678,123456789, 12344321
Example of Mismatch
Only M to N numbers can be entered
Expression ^ \ D {M, N }$ for example ^ \ D {7, 8} $
The description matches m to N numbers.
Matching example: 12345678,1234567
Example of mismatched 123456,123456789
Only numbers can be entered
Expression ^ [0-9] * $
The description matches any number.
Matching example: 12345678,1234567
Example e,
Only numbers in a certain range can be entered.
Expression ^ [12-15] $
Describe the number that matches a certain range
Matching example :,
Example of Mismatch
Only numbers with 0 and non-0 headers can be entered.
Expression ^ (0 | [1-9] [0-9] *) $
The description can be 0, the first number cannot be 0, and the number can contain 0
Matching example 101,100
Example 01,
Only real numbers can be input.
Expression ^ [-+]? \ D + (\. \ D + )? $
Description matching real number
Example 18, + 3.14,-9.90
Example of mismatched. 6, 33 S, 67-99
Only the positive number of N decimal places can be entered
Expression ^ [0-9] + (. [0-9] {n })? $ With ^ [0-9] + (. [0-9] {2 })? $ Example
Describe the positive number matching n decimal places
Example of matching 2.22
Example 2.222,-2.22,
Only the positive number of M-N decimal places can be entered
Expression ^ [0-9] + (. [0-9] {m, n })? $ With ^ [0-9] + (. [0-9] {1, 2 })? $ Example
Describe the positive number of M to N decimal places
Matching examples 2.22, 2.2
Example 2.222,-2.2222,
Only positive integers other than 0 can be entered.
Expression ^ \ +? [1-9] [0-9] * $
Describe to match a positive integer other than 0
Matching example 2, 23, 234
Example 0,-4,
Only negative integers other than 0 can be entered.
Expression ^ \-[1-9] [0-9] * $
Describe to match a non-0 negative integer
Example of matching-2,-23 and-234
Examples of unmatched values 0, 4,
Only n characters can be entered
The expression ^. {n} $ takes ^. {4} $ as an example.
The description matches n characters. Note that the Chinese character is only one character.
Matching example 1234, 12we, 123 Clear, clear moon
Mismatched example 0,123,123 WWW,
Only English characters can be entered
Expression ^. [A-Za-Z] + $
The description matches English characters and is case-insensitive.
Example of matching ASP, WWW,
Mismatched example 0,123,123 WWW,
Only uppercase English characters can be entered
Expression ^. [A-Z] + $ as an Example
Description matching uppercase English characters
Matching example net, WWW,
Mismatched example 0,123,123 WWW,
Only lowercase English characters can be entered
Expression ^. [A-Z] + $
Description matching uppercase English characters
Example of matching ASP and csdn
Example 0, net, WWW,
Only English characters and numbers can be entered
Expression ^. [A-Za-z0-9] + $ as an Example
Description matching English characters + numbers
Example of matching: 1asp, w1w1w,
Unmatched example 0,123,123, WWW,
Only English characters, numbers, and underscores can be entered.
The expression ^ \ W + $ is used as an example.
The description matches English characters, numbers, and underscores.
Example of matching: 1asp, WWW, 12,1_w
Example 3 #, 2-4, w # $,
Password example
Expression ^. [A-Za-Z] \ W {m, n} $
The description matches the M-n characters starting with an English character and can only contain numbers, letters, and underscores.
Matching example
Example of Mismatch
Upper-case verification letter
Expression \ B [^\ Wa-z0-9 _] [^ \ WA-Z0-9 _] * \ B
The first letter of the description can only be capitalized.
Example of matching ASP, Net
Example of Mismatch
Verify the URL (? Id = Chinese) vs. net2005 does not have this function
Expression ^ http: \/([\ W-] + (\. [\ W-] +) + (\/[\ W -.\/\? % & = \ U4e00-\ u9fa5] *)? $
Description verification tape? Id = Chinese
Matching example,
Http://blog.csdn.net? Id = clear moon
Example of Mismatch
Verify Chinese Characters
Expression ^ [\ u4e00-\ u9fa5] {0,} $
Description can only contain Chinese Characters
Matching example: Clear moon
Example of Mismatch
Verify QQ number
Expression [0-9] {5, 9}
Description: QQ number of 5-9 digits
Example of matching
Example of non-matching: 10000 W,
Verify email (verify the same MSN number)
Expression \ W + ([-+. '] \ W +) * @ \ W + ([-.] \ W + )*\. \ W + ([-.] \ W + )*
Description Note: MSN can use a non-hotmail.com mailbox.
Matching example aaa@msn.com
Example of non-matching 111 @ 1.
Verify the ID card number (for rough verification, it is best to tune the class library on the server side for further verification)
Expression ^ [1-9] ([0-9] {16} | [0-9] {13}) [xX0-9] $
Description
For example, if the ID card number is 15 or 18 digits, the ID card number with X is supported.
Example of Mismatch
Verify the mobile phone number (including 159, excluding PHS)
Expression ^ 13 [0-9] {1} [0-9] {8} | ^ 15 [9] {1} [0-9] {8}
The description contains the mobile phone number 159-130.
Matching example 139 XXXXXXXX
Unmatched example 140 XXXXXXXX,
Verify the phone number (very complicated, vs. net2005 gave the error)
Expression (imperfect) solution 1 (\ D {3} \) | \ D {3}-) | (\ D {4 }\) | \ D {4 }-))? (\ D {8} | \ D {7 })
Solution 2 (^ [0-9] {3, 4} \-[0-9] {3, 8} $) | (^ [0-9] {3, 8} $) | (^ \ ([0-9] {3, 4} \) [0-9] {3, 8} $) | (^ 0 {0, 1} 13 [0-9] {9} $) mobile phone numbers are supported but not perfect.
Description Shanghai: 02112345678 3 + 8 digits
Shanghai: 021-12345678
Shanghai: (021)-12345678
Shanghai: (021) 12345678
Zhengzhou: 03711234567 4 + 7 places
Hangzhou: 057112345678 4 + 8 places
There is also an extension number, country code.
Because the situation is very complex, we do not recommend that the front-end do 100% verification. So far, no one seems to be able to write a file containing all types. In fact, many situations are in conflict.
If anyone has a better phone number, leave a message.
Matching example
Example of Mismatch
Verify passport
Expression (P \ D {7}) | G \ D {8 })
Description verification P + 7 digits and G + 8 digits
Matching example
Example of Mismatch
Verify IP Address
Expression ^ (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [1-9]) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [0-9]) $
Description verification IP Address
Example of matching: 192.168.0.1 222.234.1.4
Example of Mismatch
Verification domain
Expression ^ [a-zA-Z0-9] + ([a-zA-Z0-9 \-\.] + )? \. (COM | org | net | CN | com.cn | edu.cn | grv.cn |) $
Description verification domain
Example of matching csdn.net Baidu.com it.com.cn
Example of mismatched 192.168.0.1
Verify credit card
Expression ^ ((? : 4 \ D {3}) | (? : 5 [1-5] \ D {2}) | (? : 6011) | (? : 3 [68] \ D {2}) | (? : 30 [012345] \ D) [-]? (\ D {4}) [-]? (\ D {4}) [-]? (\ D {4} | 3 [4, 7] \ D {13}) $
Description verification: Visa, MasterCard, discover, and American Express Card
Matching example
Example of Mismatch
Verify ISBN international standard document No.
Expression ^ (\ D [-] *) {9} [\ dxx] $
Description verification ISBN International Standard No.
Example of matching 7-111-19947-2
Example of Mismatch
Globally Unique guid Verification
Expression ^ [A-Z0-9] {8}-[A-Z0-9] {4}-[A-Z0-9] {4}-[A-Z0-9] {4}-[A-Z0-9] {12} $
Description format: 8-4-4-4-12
Example of matching: 2064d355-c0b9-41d8-9ef7-9d8b26524751
Example of Mismatch
Verify the file path and extension
Expression ^ ([A-Za-Z] \: |\\) \ ([^ \] + \) * [^ \/:*? "<> |] + \. Txt (l )? $
Description check path and file extension
Matching example E: \ mo.txt
Example E: \, mo.doc, E: \ mo.doc,
Verify the HTML color value
Expression ^ #? ([A-F] | [A-F] | [0-9]) {3} ([A-F] | [A-F] | [0-9]) {3 })? $
Description Check color value
Matching example # ff0000
Example of Mismatch
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/yoland/archive/2009/10/27/4731863.aspx