Only 1 digits can be entered
Expression ^\d$
Description matches a number
Examples of matches 0,1,2,3
Examples of mismatches
Only n digits can be entered
Expression ^\d{n}$ such as ^\d{8}$
Description matches 8 numbers
Examples of matches 12345678,22223334,12344321
Examples of mismatches
You can only enter at least n digits
Expression ^\d{n,}$ such as ^\d{8,}$
Description matches a minimum of n numbers
Examples of matches 12345678,123456789,12344321
Examples of mismatches
only m to n digits can be entered
Expression ^\d{m,n}$ such as ^\d{7,8}$
Description matches m to n numbers
Examples of matches 12345678,1234567
Examples of mismatches 123456,123456789
Only numbers can be entered
Expression ^[0-9]*$
Describe matching any number of numbers
Examples of matches 12345678,1234567
Example of a mismatch E,
Only one interval number can be entered
Expression ^[12-15]$
Describe numbers that match an interval
Examples of matches 12,13,14,15
Examples of mismatches
Only 0 and non-0 digits can be entered.
Expression ^ (0|[ 1-9][0-9]*) $
The description can be 0, the first number cannot be 0, and the number can have 0
Examples of matches 12,10,101,100
mismatch Example 01,
Only real numbers can be entered
Expression ^[-+]?\d+ (\.\d+)? $
Describe matching real numbers
Examples of matches 18,+3.14,-9.90
Examples of mismatches. 6,33s,67-99
Only positive real numbers with N decimal places can be entered
An expression ^[0-9]+ (. [ 0-9]{n})? $ with ^[0-9]+ (. [ 0-9]{2})? $ for example
Describe positive real numbers that match n decimal places
Example of a match 2.22
Examples of mismatches 2.222,-2.22,
Only positive real numbers with m-n decimal places can be entered
An expression ^[0-9]+ (. [ 0-9]{m,n})? $ with ^[0-9]+ (. [ 0-9]{1,2})? $ for example
Describe positive real numbers that match m to n decimal places
Examples of matches 2.22,2.2
Examples of mismatches 2.222,-2.2222,
You can only enter a positive integer that is not 0
An expression ^\+? [1-9] [0-9]*$
Describes a positive integer that matches a non 0
Examples of matches 2,23,234
Examples of mismatches 0,-4,
You can only enter a negative integer that is not 0
Expression ^\-[1-9][0-9]*$
Describe a negative integer that matches a non 0
Examples of matches -2,-23,-234
Examples of mismatches 0, 4,
Only n characters can be entered
An expression ^. {n}$ with ^. {4}$ as an example
Description matches n characters, note Chinese characters are only 1 characters
Examples of matches 1234,12we,123 Qing, qingqing Moon
Examples of mismatches 0,123,123www,
Only English characters can be entered
An expression ^. [A-za-z]+$ For example
Description match English characters, uppercase and lowercase
The matching example asp,www,
Examples of mismatches 0,123,123www,
Only uppercase English characters can be entered
An expression ^. [A-z]+$ For example
Description match English uppercase characters
The matching example net,www,
Examples of mismatches 0,123,123www,
Only lowercase English characters can be entered
An expression ^. [A-z]+$ For example
Description match English uppercase characters
Examples of matches ASP,CSDN
Examples of mismatches 0,net,www,
Only English characters + digits can be entered
An expression ^. [A-za-z0-9]+$ For example
Description match English character + number
The matching example 1ASP,W1W1W,
Examples of mismatches 0,123,123,www,
Only English characters/numbers/underscores can be entered
Expression ^\w+$ as an example
Describe matching English characters or numbers or underscores
Examples of matches 1asp,www,12,1_w
Examples of mismatches 3#,2-4,w#$,
Password examples
An expression ^. [A-za-z] \w{m,n}$
Describes m-n characters that match the beginning of an English character and can only be alphanumeric or underlined
Examples of matches
Examples of mismatches
Verify first letter Capitalization
Expression \b[^\wa-z0-9_][^\wa-z0-9_]*\b
Description first letter can only be capitalized
Examples of matches Asp,net
Examples of mismatches
Verify URL (with id= Chinese) vs.net2005 no this feature
Expression ^http:\/\/([\w-]+ (\.[ \w-]+) + (\/[\w-. \/\?%&=\u4e00-\u9fa5]*)?)? $
Description Validation band? id= Chinese
Example of a match,
Http://blog.csdn.net/?id= Qingqing Moon
Examples of mismatches
Verifying Chinese characters
Expression ^[\u4e00-\u9fa5]{0,}$
Describe only Chinese characters
Matching examples Clear the moon
Examples of mismatches
Verify QQ number
expression [0-9]{5,9}
Describe the QQ number of 5-9 digits
Examples of matches 10000,123456
Mismatch of example 10000w,
Verifying email (same as verifying MSN number)
Expression \w+ ([-+.´]\w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *
Description Note MSN with non-hotmail.com mailbox can also
Examples of matches [email protected]
Examples of mismatches [email protected].
Verify the ID number (rough, the best server-side tuning class library and further detailed verification)
Expression ^[1-9] ([0-9]{16}|[ 0-9]{13}) [xx0-9]$
Describe
Match example 15 or 18 digit ID number, support with X
Examples of mismatches
Verify the phone number (contains 159, does not contain PHS)
Expression ^13[0-9]{1}[0-9]{8}|^15[9]{1}[0-9]{8}
Description contains 159 of the phone number 130-139
Example of matching 139XXXXXXXX
Mismatch of example 140XXXXXXXX,
Verify the phone number (very complex, vs.net2005 is wrong)
Expression (imperfect) scheme one ((\ (\d{3}\) |\d{3}-) | ( \ (\d{4}\) |\d{4}-))? (\d{8}|\d{7})
Scenario Two (^[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}$) Support cell phone number but it's not perfect.
Description Shanghai: 02112345678 3+8 bit
Shanghai: 021-12345678
Shanghai: (021)-12345678
Shanghai: (021) 12345678
Zhengzhou: 03711234567 4+7 bit
Hangzhou: 057112345678 4+8 bit
And the case with the extension number, the country code.
Because the situation is very complex so do not recommend the front desk to do 100% verification, so far it seems that no one can write a containing all types, in fact, there are many situations in itself is contradictory.
If anyone has a better verification call, please leave a message.
Examples of matches
Examples of mismatches
Verify your Passport
Expression (P\d{7}) | G\D{8})
Description validation p+7 numbers and g+8 numbers
Examples of matches
Examples of mismatches
Verify IP
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 Authentication IP
Examples of matching 192.168.0.1 222.234.1.4
Examples of mismatches
Verify Domain
Expression ^[a-za-z0-9]+ ([a-za-z0-9\-\.] +)?\. (com|org|net|cn|com.cn|edu.cn|grv.cn|) $
Describe the validation domain
Examples of matching csdn.net baidu.com it.com.cn
Examples of mismatches 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 Verify Visa Card, MasterCard, Discover Card, American Express card
Examples of matches
Examples of mismatches
Verifying ISBN International Standard ISBN
Expression ^ (\d[-]*) {9}[\dxx]$
Description Verifying ISBN International Standard ISBN
Examples of matches 7-111-19947-2
Examples of mismatches
Verify GUID Global Unique identifier
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
Examples of matches 2064d355-c0b9-41d8-9ef7-9d8b26524751
Examples of mismatches
Verify file path and extension
expression ^ ([a-za-z]\:|\\) \ \ ([^\\]+\\) *[^\/:*? " <>|] +\.txt (l)? $
Description Check path and file name extension
Examples of matches E:\mo.txt
Examples of mismatches e:\, Mo.doc, E:\mo.doc,
Validating HTML color values
An expression ^#? ([a-f]| [a-f]| [0-9]) {3} ([a-f]| [a-f]| [0-9]) {3})? $
Description Check color values
Examples of matching #FF0000
Examples of mismatches
Transferred from: http://blog.csdn.net/yoland/archive/2009/10/27/4731863.aspx
Reference: Http://zhidao.baidu.com/link?url=GUDyx4ERdKXybTTDagkea9T8JIKViYB3QVUUo9P7E80WxGdyC5MaDx_94Zp9B51yhXZ_7il45TlCZm_put7HIa
A regular expression that validates a number to