"^ \ D + $" // non-negative integer (positive integer + 0) "^ [0-9] * [1-9] [0-9] * $" // positive integer "^ (-\ D +) | (0 +) $" // non-positive integer (negative integer + 0) "^-[0-9] * [1-9] [0-9] * $" // negative integer "^ -? \ D + $ "// integer "^ \ D + (\. \ d + )? $ "// Non-negative floating point number (Positive floating point number + 0) "^ ([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ "// Positive floating point number "^ (-\ D + (\. \ d + )?) | (0 + (\. 0 + )?)) $ "// Non-Positive floating point number (negative floating point number + 0) "^ (-([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ "// negative floating point number "^ (-? \ D +) (\. \ d + )? $ "// Floating point number "^ [A-Za-z] + $" // A string consisting of 26 English letters "^ [A-Z] + $" // a string consisting of 26 uppercase letters "^ [A-z] + $" // a string consisting of 26 lowercase letters "^ [A-Za-z0-9] + $" // string consisting of digits and 26 letters "^ \ W + $" // a string consisting of digits, 26 letters, or underscores "^ [\ W-] + (\. [\ w-] +) * @ [\ w-] + (\. [\ w-] +) + $ "// email address "^ [A-zA-z] +: // (\ w + (-\ w + )*)(\. (\ w + (-\ w + )*))*(\? \ S *)? $ "// Url /^ (D {2} | d {4})-(0 ([1-9] {1}) | (1 [1 | 2]) -([0-2] ([1-9] {1}) | (3 [0 | 1]) $ // year-month-day /^ (0 ([1-9] {1}) | (1 [1 | 2]) /([0-2] ([1-9] {1}) | (3 [0 | 1]) /(d {2} | d {4}) $ // month/day/year "^ ([W-.] +) @ ([0-9] {1, 3 }. [0-9] {1, 3 }. [0-9] {1, 3 }.) | ([w-] + .) +) ([a-zA-Z] {2, 4} | [0-9] {1, 3}) (]?) $ "// Emil "(D + -)? (D {4 }-? D {7} | d {3 }-? D {8} | ^ d {7, 8}) (-d + )? "// Phone number "^ (D {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]) $ "// ip addressYYYY-MM-DD basically takes into account the situation of the Year of the leap and February. ^ (1 [6-9] | [2-9] \ d) \ d {2})-(0? [1, 13578] | 1 [02])-(0? [1-9] | [12] \ d | 3 [01]) | (1 [6-9] | [2-9] \ d) \ d {2})-(0? [13456789] | 1 [012])-(0? [1-9] | [12] \ d | 30) | (1 [6-9] | [2-9] \ d) \ d {2 }) -0? 2-(0? [1-9] | 1 \ d | 2 [0-8]) | (1 [6-9] | [2-9] \ d) (0 [48] | [2468] [048] | [13579] [26]) | (16 | [2468] [048] | [3579] [26]) 00)-0? 2-29-) $ Http: // ([\ w-] + \.) + [\ w-] + (/[\ w -./? % & =] *)? --------------------------------------------------------------------------- The following is an example: Use regular expressions to restrict text box input in a webpage form: You can only enter Chinese characters using regular expressions: onkeyup = "value = value. replace (/[^ \ u4E00-\ u9FA5]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ u4E00-\ u9FA5]/g ,''))" 1. you can only enter the full-width characters: onkeyup = "value = value. replace (/[^ \ uFF00-\ uFFFF]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ uFF00-\ uFFFF]/g ,''))" 2. use a regular expression to limit that only numbers can be entered: onkeyup = "value = value. replace (/[^ \ d]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g ,''))" 3. you can only enter numbers and English letters using regular expressions: onkeyup = "value = value. replace (/[\ W]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g ,''))" 4. Calculate the length of a string (two-byte length Meter 2, ASCII character meter 1) String. prototype. len = function () {return this. replace ([^ \ x00-\ xff]/g, "aa"). length ;} 5. javascript does not have trim functions like vbscript. We can use this expression to implement it, as shown below: String. prototype. trim = function () { Return this. replace (/(^ \ s *) | (\ s * $)/g ,""); } Use regular expressions to break down and convert IP addresses: 6. The following is a Javascript program that uses regular expressions to match IP addresses and convert IP addresses to corresponding values: Function IP2V (ip) { Re =/(\ d +) \. (\ d +)/g // Regular Expression matching IP addresses If (re. test (ip )) { Return RegExp. $1 * Math. pow (255) + RegExp. $2 * Math. pow () + RegExp. $3 * + RegExp. $4*1 } Else { Throw new Error ("not a correct IP address! ") } } However, if the above program does not use regular expressions, it may be easier to directly use the split function to separate them. The program is as follows: Var ip = "10.100.0000168" Ip = ip. split (".") Alert ("the IP value is: "+ (ip [0] * 255*255*255 + ip [1] * 255*255 + ip [2] * 255 + ip [3] * 1 )) (? <=>) [^>] * (? = <) C # Regular Expression Image src [^>] * [^/]. (? : Jpg | bmp | gif )(? : \ "| \') Chinese ^ ([\ u4e00-\ u9fa5] + | [a-zA-Z0-9] +) $ URL "\ <a. +? Href = ['""] (?! Http \:\/\/)(?! Mailto \ :) (?> FoundAnchor> [^ '">] + ?) [^>] *? \>"Regular Expression matching Chinese characters: [\ u4e00-\ u9fa5] Match double-byte characters (including Chinese characters): [^ \ x00-\ xff] Regular Expression for matching empty rows: \ n [\ s |] * \ r Regular Expressions matching HTML tags:/<(. *)>. * <\/\ 1> | <(. *) \/>/ Regular Expressions matching spaces at the beginning and end: (^ \ s *) | (\ s * $) (trim functions like vbscript) The regular expression matching the Email address: \ w + ([-+.] \ w +) * @ \ w + ([-.] \ w + )*\. \ w + ([-.] \ w + )* The regular expression matching the URL: |