I turned around just to see it myself.
1. Verify the numbers:
Only 1 digits can be entered
Expression ^\d$
Description matches a number
Examples of matches 0,1,2,3
Examples of mismatches
2. 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
3. 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
4. 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
5. Only numbers can be entered
Expression ^[0-9]*$
Describe matching any number of numbers
Examples of matches 12345678,1234567
Examples of mismatches E, Qingqing Moon, Http://blog.csdn.net/21aspnet
6. 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
7. 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
Examples of mismatches 01, Qingqing Moon, Http://blog.csdn.net/21aspnet
8. 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
9. 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,http://blog.csdn.net/21aspnet
10. 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,http://blog.csdn.net/21aspnet
11. Enter only positive integers that are 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,
12. You can only enter a negative integer other than 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,
13. 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,http://blog.csdn.net/21aspnet/
14. 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,http://blog.csdn.net/21aspnet/
15. 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,
16. 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,
17. 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,http://blog.csdn.net/21aspnet/
18. 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#$,http://blog.csdn.net/21aspnet/
19. Examples of passwords
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
20. 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 http://blog.csdn.net/21aspnet/
21. Verify URL (with id= Chinese) vs.net2005 no this feature
Expression ^http:\/\/([\w-]+ (\.[ \w-]+) + (\/[\w-. \/\?%&=\u4e00-\u9fa5]*)?)? $
Description Validation band? id= Chinese
The matching example http://blog.csdn.net/21aspnet/,
Http://blog.csdn.net?id= Qingqing Moon
Examples of mismatches
22. Verifying Chinese characters
Expression ^[\u4e00-\u9fa5]{0,}$
Describe only Chinese characters
Matching examples Clear the moon
Examples of mismatches http://blog.csdn.net/21aspnet/
23. Verify QQ Number
expression [0-9]{5,9}
Describe the QQ number of 5-9 digits
Examples of matches 10000,123456
Examples of mismatches 10000w,http://blog.csdn.net/21aspnet/
24. 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] http://blog.csdn.net/21aspnet/
25. Verify the ID number (rough check, 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 http://blog.csdn.net/21aspnet/
26. 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
Examples of mismatches 140xxxxxxxx,http://blog.csdn.net/21aspnet/
27. Verify the phone number (very complicated, 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
28. Passport Verification
Expression (P\d{7}) | G\D{8})
Description validation p+7 numbers and g+8 numbers
Examples of matches
Examples of mismatches clear moon, http://blog.csdn.net/21aspnet/
29. Verify that the 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
30. Verify the domain
Expression ^[a-za-z0-9]+ ([a-za-z0-9\-\.] +)? \.s|) $
Describe the validation domain
Examples of matching csdn.net baidu.com it.com.cn
Examples of mismatches 192.168.0.1
31. 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
32. Verifying ISBN
Expression ^ (\d[-]*) {9}[\dxx]$
Description Verifying ISBN International Standard ISBN
Examples of matches 7-111-19947-2
Examples of mismatches
33. 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
34. Verify the 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, http://blog.csdn.net/21aspnet/
35. 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 http://blog.csdn.net/21aspnet/
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$
Integer or decimal: ^[0-9]+\. {0,1} [0-9] {0,2}$
Only numbers can be entered: "^[0-9]*$".
Only n digits can be entered: "^\d{n}$".
Only numbers with at least n digits can be entered: "^\d{n,}$".
You can enter only the digits of the m~n bit:. "^\d{m,n}$"
Only numbers starting with 0 and non-0 can be entered: "^ (0|[ 1-9][0-9]*) $ ".
You can only enter a positive real number with two decimal places: "^[0-9]+ (. [ 0-9]{2})? $ ".
You can only enter a positive real number with a decimal position: "^[0-9]+ (. [ 0-9]{1,3})? $ ".
You can only enter a non-zero positive integer: "^\+?" [1-9] [0-9]*$].
You can only enter a non-zero negative integer: "^\-[1-9][]0-9" *$.
Only characters with a length of 3 can be entered: "^. {3}$ ".
You can only enter a string consisting of 26 English letters: "^[a-za-z]+$".
You can only enter a string consisting of 26 uppercase English letters: "^[a-z]+$".
You can only enter a string consisting of 26 lowercase English letters: "^[a-z]+$".
You can only enter a string consisting of a number and 26 English letters: "^[a-za-z0-9]+$".
You can only enter a string consisting of a number, 26 letters, or underscores: "^\w+$".
Verify user password: "^[a-za-z]\w{5,17}$" is in the correct format: start with a letter, length between 6~18, can contain only characters, numbers, and underscores.
Verify that it contains ^%& ',; =?$\ ' characters: "[^%& ',; =?$\x22]+".
Only Chinese characters can be entered: "^[\u4e00-\u9fa5]{0,}$"
Verify email Address: "^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$ ".
Verify InternetURL: "^http://([\w-]+\.) +[\w-]+ (/[\w-./?%&=]*)? $ ".
Verify the phone number: "^ (\ (\d{3,4}-) |\d{3.4}-)? \d{7,8}$" The correct format is: "Xxx-xxxxxxx", "xxxx-xxxxxxxx", "xxx-xxxxxxx", "xxx-xxxxxxxx", " XXXXXXX "and" XXXXXXXX ".
Verify the Social Security number (15-bit or 18-digit number): "^\d{15}|\d{18}$".
Validation 12 months of the year: "^ (0?[ 1-9]|1[0-2]) $ "The correct format is:" 01 "~" 09 "and" 1 "~" 12 ".
Verify one months of 31 days: "^ ((0?[ 1-9]) | ((1|2) [0-9]) |30|31) $ "correct format for;" 01 "~" 09 "and" 1 "~" 31 ".
Regular expressions that match Chinese characters: [\U4E00-\U9FA5]
Match double-byte characters (including kanji): [^\x00-\xff]
Application: Calculates the length of a string (a double-byte character length meter 2,ascii character 1)
String.prototype.len=function () {return this.replace (/[^\x00-\xff]/g, "AA"). Length;
Regular expression that matches a blank line: \n[\s|] *\r
Regular expressions Matching HTML tags:< (. *) > (. *) <\/(. *) >|< (. *) \/>
Regular expression matching the leading and trailing spaces: (^\s*) | (\s*$)
Application: There is no trim function like VBScript in JavaScript, and we can use this expression to do the following:
String.prototype.trim = function ()
{
Return This.replace (/(^\s*) | ( \s*$)/g, "");
}
Use regular expressions to decompose and convert IP addresses:
The following is a JavaScript program that matches an IP address with a regular expression and translates an IP address into a corresponding value:
function IP2V (IP)
{
re=/(\d+) \. (\d+) \. (\d+) \. (\d+)/g//matching regular expressions for IP addresses
if (Re.test (IP))
{
Return Regexp.$1*math.pow (255,3)) +regexp.$2*math.pow (255,2)) +regexp.$3*255+regexp.$4*1
}
Else
{
throw new Error ("not a valid IP address!")
}
}
However, the above program without regular expression, and directly with the split function decomposition may be more simple, the program is as follows:
var ip= "10.100.20.168"
Ip=ip.split (".")
Alert ("IP value is:" + (IP[0]*255*255*255+IP[1]*255*255+IP[2]*255+IP[3]*1))
Regular expression matching email address: \w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *
Regular expression matching URL URL:/http ([\w-]+\.) +[\w-]+ (/[\w-./?%&=]*)?
Use regular expressions to restrict the entry of text boxes in Web Forms:
Use regular expression restrictions to enter only Chinese: onkeyup= "value=value.replace (/[^\u4e00-\u9fa5]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\u4e00-\u9fa5]/g, ') "
Restrict only full-width characters with regular expressions: onkeyup= "Value=value.replace (/[^\uff00-\uffff]/g,") "Onbeforepaste=" Clipboarddata.setdata (' Text ', Clipboarddata.getdata (' text '). Replace (/[^\uff00-\uffff]/g, ')) "
Use regular expression restrictions to enter only numbers: onkeyup= "Value=value.replace (/[^\d]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ')) "
Use regular expression restrictions to enter only numbers and English: onkeyup= "Value=value.replace (/[\w]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ')) "
<input onkeyup= "Value=value.replace (/[^\u4e00-\u9fa5\w]/g, ')" onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\u4e00-\u9fa5\w]/g, ') "value=" allow underscore, alphanumeric and kanji ">
<script language= "JavaScript" >
if (document.layers)//Trigger keyboard event
Document.captureevents (event.keypress)
function XZ (thsv,nob) {
if (nob== "2") {
Window.clipboardData.setData ("Text", "" ")
Alert ("Avoid illegal character input, do not copy characters");
return false;
}
if (event.keycode!=8 && event.keycode!=16 && event.keycode!=37 && event.keycode!=38 && event.keycode!=39 && event.keycode!=40) {
thsvv=thsv.value;//the value entered
Thsvs=thsvv.substring (thsvv.length-1);//The last character entered
Thsvss=thsvv.substring (0,thsvv.length-1);//Remove the last error character
if (!thsvs.replace (/[^\u4e00-\u9fa5\w]/g, ') | | event.keycode==189) {//Regular drop symbol and underscore key
Thsv.value= ' do not enter illegal symbols [' +thsvs+ '];
Alert (' Do not enter illegal symbols [' +thsvs+ '] ');
Thsv.value= "";
return false;
}
}
}
</script>
<input onkeyup= "XZ (this,1)" onpaste= "XZ (this,2)" value= "" > Allow alphanumeric letters and kanji
<script language= "JavaScript" >
<!--
function MaxLength (field,maxlimit) {
var j = field.value.replace (/[^\x00-\xff]/g, "* *"). Length;
Alert (j);
var Tempstring=field.value;
var tt= "";
if (J > Maxlimit) {
for (Var i=0;i<maxlimit;i++) {
if (Tt.replace (/[^\x00-\xff]/g, "* *"). Length < Maxlimit)
tt = TEMPSTRING.SUBSTR (0,i+1);
Else
Break
}
if (Tt.replace (/[^\x00-\xff]/g, "* *"). Length > Maxlimit)
Tt=tt.substr (0,tt.length-1);
Field.value = TT;
}else{
;
}
}
</script>
Single-line text box control <br/>
<input type= "text" id= "Text1" name= "Text1" onpropertychange= "MaxLength (this, 5)" ><br/>
Multiline text box control: <br/>
<textarea rows= "14"
cols= "id=" Textarea1 "name=" Textarea1 "onpropertychange=" MaxLength (This,) "></textarea><br/>
Control the contents of the form can only enter numbers, Chinese ....
<script>
function test ()
{
if (DOCUMENT.A.B.VALUE.LENGTH>50)
{
Alert ("Cannot exceed 50 characters!") ");
Document.a.b.focus ();
return false;
}
}
</script>
<form name=a onsubmit= "return Test ()" >
<textarea name= "B" cols= "+" wrap= "VIRTUAL" rows= "6" ></textarea>
<input type= "Submit" name= "Submit" value= "Check" >
</form>
Can only be Chinese characters
<input onkeyup= "Value=value.replace (/[^\u4e00-\u9fa5]/g, ')" >
can only be English characters
<script language=javascript>
function Onlyeng ()
{
if (! ( EVENT.KEYCODE>=65&&EVENT.KEYCODE<=90))
Event.returnvalue=false;
}
</script>
<input onkeydown= "Onlyeng (); >
<input name= "Coname" type= "text" size= "" maxlength= "+" class= "Input2" onkeyup= "Value=value.replace (/[\w]/g, ') "Onbeforepaste=" clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ')) ">
Can only be a number
<script language=javascript>
function Onlynum ()
{
if (! ( (event.keycode>=48&&event.keycode<=57) | | (event.keycode>=96&&event.keycode<=105)))
Consider the numeric keys on the keypad
Event.returnvalue=false;
}
</script>
<input onkeydown= "Onlynum (); >
can only be English characters and numbers
<input onkeyup= "Value=value.replace (/[\w]/g, ')" onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ')) ">
Verify to email format
<script Language=javascript runat=server>
function Isemail (stremail) {
if (Stremail.search (/^\w+ (-\w+) | ( \.\w+)) *\@[a-za-z0-9]+ ((\.| -) [a-za-z0-9]+] *\. [a-za-z0-9]+$/)! =-1)
return true;
Else
Alert ("Oh");
}
</SCRIPT>
<input type=text onblur=isemail (this.value) >
Mask keyword (sex, fuck)-Modified
<script language= "JavaScript1.2" >
function Test () {
if ((A.b.value.indexof ("sex") = = 0) | | (A.b.value.indexof ("fuck") = = 0)) {
Alert ("Four Graces and three Passions");
A.b.focus ();
return false;}
}
</script>
<form name=a onsubmit= "return Test ()" >
<input Type=text name=b>
<input type= "Submit" name= "Submit" value= "Check" >
</form>
You can only enter numbers in the Limit text box
Mobile Number: (^ (\d{3,4}-)? \d{7,8}) $| (13[0-9]{9}) | (15[8-9]{9})
No, you can do it according to the above introduction, it just takes a little time.
Regular expression set for validating numbers
Verification Number: ^[0-9]*$
To verify N-bit numbers: ^\d{n}$
Verify that at least n digits: ^\d{n,}$
Verify the number of m-n bits: ^\d{m,n}$
Verify numbers starting with 0 and non 0: ^ (0|[ 1-9][0-9]*) $
Verify that there is a positive real number with two decimal places: ^[0-9]+ (. [ 0-9]{2})? $
Verify that there is a positive real number with 1-3 decimal places: ^[0-9]+ (. [ 0-9]{1,3})? $
Verify non-zero positive integers: ^\+? [1-9] [0-9]*$
To verify a nonzero negative integer: ^\-[1-9][0-9]*$
Validates non-negative integers (positive integers + 0) ^\d+$
Validates a non-positive integer (negative integer + 0) ^ ((-\d+) | ( 0+)) $
Verify the character with a length of 3: ^. {3}$
Validates a string consisting of 26 English letters: ^[a-za-z]+$
Validates a string consisting of 26 uppercase English letters: ^[a-z]+$
Validates a string consisting of 26 lowercase English letters: ^[a-z]+$
Validates a string consisting of a number and 26 English letters: ^[a-za-z0-9]+$
Validates a string consisting of a number, 26 letters, or underscores: ^\w+$
Verify user password: ^[a-za-z]\w{5,17}$ the correct format is: Start with a letter, the length is between 6-18, and can contain only characters, numbers, and underscores.
Verify that it contains ^%& ',; =?$\ ' characters:[^%& ', =?$\x22]+
Verify Kanji: ^[\u4e00-\u9fa5],{0,}$
Verify email Address: ^\w+[-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$
Verify interneturl:^http://([\w-]+\.) +[\w-]+ (/[\w-./?%&=]*)? $; ^[a-za-z]+://(w+ (-w+) *) (. ( w+ (-w+) *) * (? s*)? $
Verify the phone number: ^ (\ (\d{3,4}\) |\d{3,4}-)? \d{7,8}$:--the correct format is: xxxx-xxxxxxx,xxxx-xxxxxxxx,xxx-xxxxxxx,xxx-xxxxxxxx,xxxxxxx, XXXXXXXX.
Verify your Social Security number (15-bit or 18-digit number): ^\d{15}|\d{}18$
Validation 12 months of the year: ^ (0?[ 1-9]|1[0-2]) $ correct format: "01"-"09" and "1" "12"
Verify one months of 31 days: ^ ((0?[ 1-9]) | ((1|2) [0-9]) |30|31) $ The correct format is: 01, 09 and 1, 31.
Integer: ^-?\d+$
Non-negative floating-point number (positive floating point + 0): ^\d+ (\.\d+)? $
Positive floating-point number ^ ([0-9]+\.[ 0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*\. [0-9]+) | ([0-9]*[1-9][0-9]*)) $
Non-positive floating-point number (negative floating point + 0) ^ ((-\d+ (\.\d+)?) | (0+ (\.0+)?)) $
Negative floating-point number ^ (-([0-9]+\.[ 0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*\. [0-9]+) | ([0-9]*[1-9][0-9]*))) $
Floating point ^ (-?\d+) (\.\d+)?
Regular expression instance (GO)