1. Verify the number: Only 1 numeric expression ^\d$ can be entered to describe an example that matches a number match 0,1,2,3 mismatch example 2. You can enter only n numeric expressions ^\d{n}$ such as ^\d{8}$ description match 8 digit match Example 123
Example of 45678,22223334,12344321 mismatch 3. You can enter at least n numeric expressions ^\d{n,}$ such as ^\d{8,}$ to describe an example that matches at least n digits 12345678,123456789,12344321
Examples of mismatches 4. You can only enter m to n numeric expression ^\d{m,n}$ such as the ^\d{7,8}$ description matches the example of M to n number matching 12345678,1234567 The example of mismatch 123456,123456789 5. Only numbers can be entered The expression ^[0-9]*$ Describes an example of matching any number matching 12345678,1234567 An example E, Qingqing month 6. You can only enter an interval numeric expression ^[12-15]$ Describe an example of matching a number matching an interval 12,13 , 14,15 does not match the example 7. You can only enter numeric expressions that start with 0 and not 0 ^ (0|[ 1-9][0-9]*) $ description can be 0, the first number cannot be 0, the number can have 0 matching examples 12,10,101,100 Mismatched example 01, qingqing Moon, Http://blog.csdn.net/21aspnet 8. You can only enter a real-expression ^[-+]?\d+ (\.\d+)? $ describes examples of matching real-match examples 18,+3.14,-9.90 mismatches. 6,33s,67-99 9. Positive real-number expression ^[0-9]+ (. [ 0-9]{n})? $ with ^[0-9]+ (. [ 0-9]{2})? $ For example to describe the example 2.22 mismatch of positive real numbers matching N-bit decimals 2.222,-2.22,http://blog.csdn.net/21aspnet 10. Positive real-number expressions that can only enter M-n decimal places ^[0-9]+ (. [0-9] {m,n})? $ with ^[0-9]+ (. [ 0-9]{1,2})? $ is an example of a positive real number match that matches m to n decimal digits 2.22,2.2 An example of a mismatch 2.222,-2.2222,httP://blog.csdn.net/21aspnet 11. Can only enter a positive integer expression ^\+ not 0? [1-9] [0-9]*$ Describes an example of a positive integer matching a non-0 case 2,23,234 Mismatch example 0,-4, 12. Only non-0 negative integer expressions can be entered ^\-[1-9][0-9]*$ An example that describes a negative integer match that is not 0 -2,-23,-234 Examples of matches 0, 4, 13. You can enter only n-character expressions ^. {n}$ with ^.
{4}$ For example to match n characters, note that Chinese characters only count to 1 characters match the example 1234,12we,123 clear, qingqing month son mismatch example 0,123,123WWW,HTTP://BLOG.CSDN.NET/21ASPNET/14. You can only enter English characters An expression ^. [a-za-z]+$, for example, describes matching English characters, case-by-case asp,www, mismatched example 0,123,123WWW,HTTP://BLOG.CSDN.NET/21ASPNET/15. You can enter only uppercase English character expressions ^.[ a-z]+$, for example, describes matching English uppercase character matching examples net,www, mismatched example 0,123,123www, 16. You can only enter lowercase English character expressions ^. [A-z]+$ is an example of an example that matches an English uppercase character match asp,csdn An example of a mismatch 0,net,www, 17. You can only enter English characters + numeric expressions ^.
[a-za-z0-9]+$ For example describes matching English characters + number matching examples 1asp,w1w1w, mismatched examples of 0,123,123,WWW,HTTP://BLOG.CSDN.NET/21ASPNET/18. Only English characters/digits/underscores can be entered The expression ^\w+$ is an example of an example that matches an English character or a number or an underscore match 1asp,www,12,1_w an instance of an unmatched 3#,2-4,w#$,http://blog.csdn.net/21aspnet/19. password example expression ^. [a-za-z]\w{m,n}$ An example that matches the m-n bit character at the beginning of the English character and can only be matched by a number of letters or underscores 20. Verify the initial capitalization expression \b[^\wa-z0-9_][^\wa-z0-9_]*\b the first letter can only beUppercase Match Example Asp,net mismatched example 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 matching example http://blog.csdn.net/21aspnet/, http://blog.csdn.net?id= clear month son mismatch example 22. Verifying the expression of Chinese characters ^[\u4e00-\u9f A5]{0,}$ describes only Chinese characters matching examples of qingqing Moon mismatch http://blog.csdn.net/21aspnet/23. Verify QQ number expression [0-9]{5,9} describes 5-9-bit QQ Number matching example 10000, 123456 mismatched examples 10000w,http://blog.csdn.net/21aspnet/24. Verify e-mail (verify MSN number) expression \w+ ([-+. '] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) * Description Note that MSN can also match the example of a Hotmail.com mailbox aaa@msn.com mismatched example 111@1. HTTP://BLOG.CSDN.NET/21ASPNET/25. Verify the identity card number (rough check, best server-side Tune class Library again fine verification) expression ^[1-9] ([0-9]{16}|[ 0-9]{13}) [xx0-9]$ describes the matching example 15 or 18-bit ID number, supporting an example of a mismatch with X HTTP://BLOG.CSDN.NET/21ASPNET/26. Verify that the mobile number (including 159, does not contain PHS) expression ^13[0 -9]{1}[0-9]{8}|^15[9]{1}[0-9]{8} Describes the example of 139XXXXXXXX mismatch with 159 mobile number 130-139 matches example 140xxxxxxxx,http://blog.csdn.net/ 21ASPNET/27. Verify phone number (very complex, VS. NET2005 is wrong. expression (imperfect) scheme 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 description Shanghai: 02112345678 3+8 Shanghai: 021-12345678 Shanghai: (021)-12345678 Shanghai: (021) 12345678 Zhengzhou: 037112345
67 4+7 Hangzhou: 057112345678 4+8 bit also has the extension number, the country code situation because the situation is very complex therefore does not recommend the front desk to do 100% verification, so far does not seem to be able to write a contains all types, actually has many situations in itself is contradictory. If anyone has a better authentication call please leave a message matching example mismatch example 28. Verify Passport expression (P\d{7}) | G\D{8}) Describes the example of validation p+7 numbers and g+8 matching examples of a mismatch between Qingqing Moon, http://blog.csdn.net/21aspnet/29. Verifying 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 Match example 192.168.0.1 222.234.1.4 mismatch Example 30. Verify the domain expression ^[a-za-z0-9]+ ([a-za-z0-9\-\.] +)? \.s|) $ Description Validation Domain Match example csdn.net baidu.com it.com.cn mismatch Example 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 Verification Visa Card, MasterCard, Discover Card, American Express card matching example mismatch example 32. Verifying ISBN international ISBN expression ^ (\d[-]*) {9}[\dxx]$ description ID ISBN matching Example 7-111-19947-2 unmatched example 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 Matching example 2064d355-c0b9-41d8-9ef7-9d8b26524751 mismatch example 34. Verify file path and extension expression ^ ([a-za-z]\:|\\) \ ([^\\ ]+\\)*[^\/:*?" <>|] +\.txt (L)? $ description Check path and file name extension match examples E:\mo.txt mismatched examples e:\, Mo.doc, E:\mo.doc, http://blog.csdn.net/21aspnet/35. Validating HTML colors Value Expression ^#? ([a-f]| [a-f]| [0-9]) {3} ([a-f]| [a-f]| [0-9]) {3})? $ description Check Color value Matching example #FF0000 mismatched example 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}$ can only enter a number: ' ^[0-9]*$ '.
Only n digits can be entered: "^\d{n}$".
You can enter at least n digits: "^\d{n,}$". You can enter only the number of m~n digits:. "^\d{m,n}$" can only enter numbers beginning with 0 and not 0: "^" (0|[
1-9][0-9]*) $ ". You can only enter positive real numbers with two decimal digits: ^[0-9]+ (. [
0-9]{2})? $ ". You can only enter positive real numbers with 1~3 decimal places: ^[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 "*$. You can only enter characters with a length of 3: "^.
{3}$ ".
You can only enter a string of 26 English letters: "^[a-za-z]+$".
You can only enter a string consisting of 26 uppercase 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 numbers and 26 English letters: "^[a-za-z0-9]+$".
You can only enter a string of numbers, 26 English letters, or underscores: "^\w+$".
Verify user password: "^[a-za-z]\w{5,17}$" is the correct format: start with a letter, length between 6~18, can only contain characters, numbers, and underscores.
Verify that there are ^%& ',; =?$\ ' and other characters: "[^%& ',; =?$\x22]+". Can only enter Chinese characters: "^[\u4e00-\u9fa5]{0,}$" Verify email Address: "^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.]
\w+) *$ ". Verify InternetURL: "^http://([\w-]+\.)
+[\w-]+ (/[\w-./?%&=]*)? $ ". Verify 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 ID Number (15-bit or 18-digit): "^\d{15}|\d{18}$". Verify 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) $ "the correct format is;" 01 "~" 09 "and" 1 "~" 31 ". A regular expression that matches a Chinese character: [\u4e00-\u9fa5] matches double-byte characters (including Chinese characters): [^\x00-\xff] Apply: Computes 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;} A regular expression that matches a blank row: \n[\s|] *\r matching HTML Label Regular Expression:< (. *) > (. *) <\/(. *) >|< (. *) \/> matching a regular expression with a trailing space: (^\s*) | (\s*$) Application: JavaScript does not have a trim function like VBScript, we can use this expression to implement, as follows: String.prototype.trim = function () {return this.repla CE (/(^\s*) | (
\s*$)/g, ""); Use regular expressions to decompose and transform IP addresses: The following is a JavaScript program that uses regular expressions to match an IP address and converts an IP address to a corresponding numeric value: function IP2V (IP) {re=/(\d+) \. ( \d+) \. (\d+) \. (\d+)/g//matching IP address regular expression 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, if the above program does not use regular expressions, the Split function can be used directly to decompose the procedure 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)") matches the regular expression of an email address: \w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) * Matching the URL of the regular expression: http://([\w-]+\.)
+[\w-]+ (/[\w-/?%&=]*)? Using regular expressions to restrict text box entries in a Web page form: 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, ') ' restricts only full-width characters in regular expression: onkeyup= "Value=value.replace (/[^\uff00-\uffff]/g,") "onbeforepaste="
Clipboarddata.setdata (' Text ', Clipboarddata.getdata (' text '). Replace (/[^\uff00-\uffff]/g, ') " Only numbers can be entered with regular expression restrictions: onkeyup= "Value=value.replace (/[^\d]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ') "Restrict only numbers and English in regular expression: 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=" allows underscores, alphanumeric letters and Chinese characters "> <script language=" JavaScript ' > if (document.layers)//Triggers 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 remove symbol and underscore key thsv.value= ' do not enter illegal symbol [' +thsvs+ '] ';
Alert (' Do not enter illegal symbols [' +thsvs+ '] ');
Thsv.value= "";
return false; }} </script> <input onkeyup= "XZ (this,1)" onpaste= "XZ (this,2)" value= "" > Allow numeric 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 = TEM
Pstring.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/> Multi-line text box control: <br/> <textarea rows=" "cols=" "" Id= "Textarea1" name= "Textarea1" Onpropertyc Hange= "MaxLength (This)" ></textarea><br/> Control Form content 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 kanji <input onkeyup = "Value=value.replace (/[^\u4e00-\u9fa5]/g, ')" > can only be English characters <script language=javascript> function Onlyeng () {i F (!) (
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 digital < The script language=javascript> function Onlynum () {if (! (event.keycode>=48&&event.keycode<=57) | |
(event.keycode>=96&&event.keycode<=105)))
Consider the number key event.returnvalue=false on the keypad; } </script> <input onkeydown= "Onlynum ();" > can only be English characters and digital <input onkeyup= "Value=value.replace (/[\w]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ') "> validated as 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 ("Shime three Loves");
A.b.focus ();
return false;} } </script> <form name=a onsubmit= "return Test ()" > <input type=text name=b> <input "Submit" Name= "Submit" value= "Check" > </form> restricted text box can only enter the number <input onkeyup= "If" Event.keycode!=37 && event. KeyCode!=) value=value.replace (/\d/g, '); " Onbeforepaste= "Clipboarddata.setdata" (' Text ', Clipboarddata.getdata (' text '). Replace (/\d/g, ') "> Mobile number: (^ (\d{ 3,4}-) \d{7,8}) $| (13[0-9]{9}) |
(15[8-9]{9}) can also be based on the introduction of the written out, it will only take a little time. To validate a regular expression set of numbers: ^[0-9]*$ Verify N-bit numbers: ^\d{n}$ validate at least n digits: ^\d{n,}$ Verify m-n bit numbers: ^\d{m,n}$ verify numbers starting with 0 and non 0: ^ (0|[ 1-9][0-9]*) $ verifies positive real number with two decimal digits: ^[0-9]+ (. [ 0-9]{2})? $ verifies positive real number with 1-3 decimal digits: ^[0-9]+ (. [ 0-9]{1,3})? $ verify Non-zero positive integer: ^\+? [1-9] [0-9]*$ validation Non-zero integer: ^\-[1-9][0-9]*$ validation of nonnegative integers (positive integer + 0) ^\d+$ validation of non positive integers (negative integers + 0) ^ ((-\d+) | ( 0+) $ to verify the character with length 3: ^. {3}$ validates a 26-letter string: ^[a-za-z]+$ validationA string of 26 uppercase letters: ^[a-z]+$ validates a string of 26 lowercase English letters: ^[a-z]+$ validates a string of numbers and 26 English letters: ^[a-za-z0-9]+$ validation consists of numbers,
26 Letter or underscore string: ^\w+$ Authentication User password: ^[a-za-z]\w{5,17}$ the correct format is: Start with a letter, length between 6-18, can only contain characters, numbers and underscores. Verify that it contains ^%& ',; =?$\ ' and other characters:[^%& ', =?$\x22]+ verify Chinese characters: ^[\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 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 ID Number (15-bit or 18-digit): ^\d{15}|\d{}18$ verification of the 12 months of the year: ^ (0?[ 1-9]|1[0-2]) $ The correct format is: "01"-"09" and "1" "12" validation one day of the month: ^ (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 number + 0): ^\d+ (\.\d+)? $ positive float ^ ([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 number + 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+)?
The above is the commonly used regular expression in this article, and I hope it will be helpful for us to learn regular expressions.