This article implements the following:
Only 1 digits can be entered
Only n digits can be entered
You can enter at least n digits
only m to n digits can be entered
Only numbers can be entered
Only one interval number can be entered
You can only enter numbers that begin with 0 and not 0
Only real numbers can be entered
Positive real numbers that can only be entered N decimal places
Only positive real numbers with m-n decimal digits can be entered
Only positive integers that are not 0 can be entered
Only negative integers that are not 0 can be entered
Only n characters can be entered
Only English characters can be entered
Only uppercase English characters can be entered
Only lowercase English characters can be entered
Only English characters + digits can be entered
Only English characters/digits/underscores can be entered
Examples of passwords
Verify first letter Capitalization
Verify URL (with id= Chinese) vs.net2005 no this feature
Verifying Chinese characters
Verify QQ number
Verify e-mail (verify MSN number)
Verify the identity card number (rough check, the best server-side tuning class library again fine verification)
Verify mobile phone number (including 159, does not contain PHS)
Verify phone number (very complex, vs.net2005 is wrong)
Verify Passport
Verify IP, verify domain authentication credit card (support Visa Card, MasterCard, Discover, American Express card)
Verify ISBN International Standard ISBN
Verify GUID Global Unique identifier
Verifying file paths and extensions
Validating HTML color values
... ...
I know
I've always had a pair of invisible wings.
Take me to fly
Give me hope.
I finally
See
All the dreams are blooming
Chasing the young
... ...
--------------- singer: Angela -han album: Pandora
The regular expression is. NET invisible syntax. There are a lot of articles about its syntax, and you can also refer to MSDN. The purpose of this article is to provide examples, including all regular expression usage, will continue to supplement, welcome to leave a message to support.
The following links have a sufficient number of basic tutorials:
Http://blog.csdn.net/21aspnet/category/285967.aspx
RegularExpressionValidator control
Use the RegularExpressionValidator control, and of course you can validate it directly in the background without the RegularExpressionValidator control
The ValidationExpression property has several default authentication methods, but that is far from enough . The ErrorMessage property is an error message.
As shown in the picture, you can click the "..." pop-up window to select the regular expression you want, or write directly to yourself .
In IE, input is not the corresponding format will be the error :
Verify Number:
Only 1 digits can be entered
|
An expression |
^/d$ |
Describe |
Match a number |
Examples of matches |
0,1,2,3 |
Examples of mismatches |
|
only n digits can be entered
|
An expression |
^/d{n}$ For example ^/d{8}$ |
Describe |
Match 8 digits |
Examples of matches |
12345678,22223334,12344321 |
Examples of mismatches |
|
You can enter at least n digits
|
An expression |
^/d{n,}$ For example ^/d{8,}$ |
Describe |
Match at least n digits |
Examples of matches |
12345678,123456789,12344321 |
Examples of mismatches |
|
only m to n digits can be entered
|
An expression |
^/d{m,n}$ For example ^/d{7,8}$ |
Describe |
Match m to n digits |
Examples of matches |
12345678,1234567 |
Examples of mismatches |
123456,123456789 |
only numbers can be entered
|
An expression |
^[0-9]*$ |
Describe |
Match any number |
Examples of matches |
12345678,1234567 |
Examples of mismatches |
E, Qingqing Moon, Http://blog.csdn.net/21aspnet |
only one interval number can be entered
|
An expression |
^[12-15]$ |
Describe |
Match a number in an interval |
Examples of matches |
12,13,14,15 |
Examples of mismatches |
|
You can only enter numbers that begin with 0 and not 0
|
An expression |
^ (0| [1-9] [0-9]*) $ |
Describe |
Can be 0, the first number cannot be 0, and the number can have 0 |
Examples of matches |
12,10,101,100 |
Examples of mismatches |
01, Qingqing Moon, Http://blog.csdn.net/21aspnet |
only real numbers can be entered
|
An expression |
^[-+]?/d+ (/./d+)? $ |
Describe |
Matching real numbers |
Examples of matches |
18,+3.14,-9.90 |
Examples of mismatches |
.6,33s,67-99 |
positive real numbers that can only be entered N decimal places
|
An expression |
^[0-9]+ (. [ 0-9]{n})? $ with ^[0-9]+ (. [ 0-9]{2})? $ for example |
Describe |
Positive real numbers that match n decimal digits |
Examples of matches |
2.22 |
Examples of mismatches |
2.222,-2.22,http://blog.csdn.net/21aspnet |
only positive real numbers with m-n decimal digits 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 digits |
Examples of matches |
2.22,2.2 |
Examples of mismatches |
2.222,-2.2222,http://blog.csdn.net/21aspnet |
only positive integers that are not 0 can be entered
|
An expression |
^/+? [1-9] [0-9]*$ |
Describe |
Match a positive integer that is not 0 |
Examples of matches |
2,23,234 |
Examples of mismatches |
0,-4, |
only negative integers that are not 0 can be entered
|
An expression |
^/-[1-9][0-9]*$ |
Describe |
Matches a negative integer that is not 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 |
Describe |
Match n characters, note that Chinese characters are only 1 characters |
Examples of matches |
1234,12we,123 Qing, qingqing Moon |
Examples of mismatches |
0,123,123www,http://blog.csdn.net/21aspnet/ |
only English characters can be entered
|
An expression |
^. [a-za-z]+$ as an example |
Describe |
Match English characters, any case |
Examples of matches |
Asp,www, |
Examples of mismatches |
0,123,123www,http://blog.csdn.net/21aspnet/ |
only uppercase English characters can be entered
|
An expression |
^. [a-z]+$ as an example |
Describe |
Match uppercase characters in English |
Examples of matches |
Net,www, |
Examples of mismatches |
0,123,123www, |
only lowercase English characters can be entered
|
An expression |
^. [a-z]+$ as an example |
Describe |
Match uppercase characters in English |
Examples of matches |
Asp,csdn |
Examples of mismatches |
0,net,www, |
only English characters + digits can be entered
|
An expression |
^. [a-za-z0-9]+$ as an example |
Describe |
Match English characters + numbers |
Examples of matches |
1ASP,W1W1W, |
Examples of mismatches |
0,123,123,www,http://blog.csdn.net/21aspnet/ |
only English characters/digits/underscores can be entered
|
An expression |
^/w+$ as an example |
Describe |
Match English characters or numbers or underscores |
Examples of matches |
1asp,www,12,1_w |
Examples of mismatches |
3#,2-4,w#$,http://blog.csdn.net/21aspnet/ |
Examples of passwords
|
An expression |
^. [a-za-z]/w{m,n}$ |
Describe |
Matches the m-n bit character at the beginning of the English character and can only be alphanumeric or underlined |
Examples of matches |
|
Examples of mismatches |
|
Verify first letter Capitalization
|
An expression |
/b[^/wa-z0-9_][^/wa-z0-9_]*/b |
Describe |
The first letter can only be capitalized |
Examples of matches |
Asp,net |
Examples of mismatches |
http://blog.csdn.net/21aspnet/ |
Verify URL (with id= Chinese) vs.net2005 no this feature
|
An expression |
^http:////([/w-]+ (/.[ /w-]+) + (//[/w-.///?%&=/u4e00-/u9fa5]*)? $ |
Describe |
Verification band Id= Chinese |
Examples of matches |
http://blog.csdn.net/21aspnet/, http://blog.csdn.net?id= qingqing Month son |
Examples of mismatches |
|
Verifying Chinese characters
|
An expression |
^[/u4e00-/u9fa5]{0,}$ |
Describe |
Only Chinese characters |
Examples of matches |
Qingqing Moon |
Examples of mismatches |
http://blog.csdn.net/21aspnet/ |
Verify QQ number
|
An expression |
[0-9] {5,9} |
Describe |
5-9-digit QQ number |
Examples of matches |
10000,123456 |
Examples of mismatches |
10000w,http://blog.csdn.net/21aspnet/ |
Verify e-mail (verify MSN number) |
An expression |
/w+ ([-+. '] /w+) *@/w+ ([-.] /w+) */./w+ ([-.] /w+) * |
Describe |
Note that MSN with a non-Hotmail.com mailbox can also |
Examples of matches |
Aaa@msn.com |
Examples of mismatches |
111@1. http://blog.csdn.net/21aspnet/ |
Verify the identity card number (rough check, the best server-side tuning class library again fine verification)
|
An expression |
^[1-9] ([0-9]{16}|[ 0-9]{13}) [xx0-9]$ |
Describe |
|
Examples of matches |
15 or 18-digit ID number, support with X |
Examples of mismatches |
http://blog.csdn.net/21aspnet/ |
Verify mobile phone number (including 159, does not contain PHS)
|
An expression |
^13[0-9]{1}[0-9]{8}|^15[9]{1}[0-9]{8} |
Describe |
Contains 159 of mobile phone number 130-139 |
Examples of matches |
139XXXXXXXX |
Examples of mismatches |
140xxxxxxxx,http://blog.csdn.net/21aspnet/ |
Verify phone number (very complex, vs.net2005 is wrong)
|
Expression (Imperfect) |
Option One ((/(/d{3}/) |/d{3}-) | ( /(/d{4}/) |/d{4}-))? (/d{8}|/d{7}) Programme II (^[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 also not perfect |
Describe |
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 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 there seems to be no one can write a containing all types , in fact, there are many situations in itself is contradictory. If anyone has a better authentication call, leave a message. |
Examples of matches |
|
Examples of mismatches |
|
Verify Passport
|
An expression |
(P/d{7}) | G/D{8}) |
Describe |
Verify p+7 numbers and g+8 numbers |
Examples of matches |
|
Examples of mismatches |
Qingqing Moon, http://blog.csdn.net/21aspnet/ |
Verifying IP
|
An 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]) $ |
Describe |
Verifying IP |
Examples of matches |
192.168.0.1 222.234.1.4 |
Examples of mismatches |
|
Verify Domain |
An expression |
^[a-za-z0-9]+ ([a-za-z0-9/-/.] +)?/. (com|org|net|cn|com.cn|edu.cn|grv.cn|) $ |