Verify the regular expression of a number.
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