Use Regular Expressions

Source: Internet
Author: User

The following describes the verification functions and expressions used to verify the control using regularexpressionvalidator:

Only numbers can be entered: "^ [0-9] * $"
Only n digits can be entered: "^ d {n} $" matches n digits "/d {n }".
You can only enter at least N digits: "^ d {n,} $"
Only M-N digits can be entered: "^ d {m, n} $"
Only numbers starting with zero and non-zero can be entered: "^ (0 | [1-9] [0-9] *) $"
Only positive numbers with two decimal places can be entered: "^ [0-9] + (. [0-9] {2 })? $"
You can only enter a positive number with 1-3 decimal places: "^ [0-9] + (. [0-9] {1, 3 })? $"
Only a non-zero positive integer can be entered: "^ +? [1-9] [0-9] * $"
Only a non-zero negative integer can be entered: "^-[1-9] [0-9] * $"
Only 3 characters can be entered: "^. {3} $"
You can only enter a string consisting of 26 English letters: "^ [A-Za-Z] + $"
Only a string consisting of 26 uppercase letters can be entered: '^ [A-Z] + $"
You can only enter a string consisting of 26 lower-case English letters: "^ [A-Z] + $"
You can only enter a string consisting of a number and 26 English letters: '^ [A-Za-z0-9] + $"
Only a string consisting of digits, 26 English letters, or underscores can be entered: "^ W + $"
Verify User Password: "^ [A-Za-Z] W {5, 17} $" is in the correct format: it must start with a letter and be between 6 and 18 characters in length,
Verification password: starts with a letter, at least 6 [a-zA-Z0-9] {5, 17}

It can only contain characters, numbers, and underscores.
Check whether ^ % & ',; =? $ "And other 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 -./? % & =] *)? $"
Verification phone number: "^ (d {3, 4}) | D {3, 4 }-)? D {7, 8} $"

Correct format: XXXX-XXXXXXX, XXXX-XXXXXXXX, XXX-XXXXXXX ",

XXX-XXXXXXXX, xxxxxxx, XXXXXXXX ".
Verify the ID card number (15 or 18 digits): "^ d {15} | D {} 18 $"
12 months of verification: "^ (0? [1-9] | 1 [0-2]) $ "the correct format is:" 01 "-" 09 "and" 1 "" 12"
31 days of verification for a month: "^ (0? [1-9]) | (1 | 2) [0-9]) | 30 | 31) $"

The correct format is "01", "09", and "1", "31 ".

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:/<(. *)>. * | <(. *)/>/
Regular Expression matching the first and last spaces: (^ s *) | (S * $)
Regular Expression matching the email address: W + ([-+.] W +) * @ w + ([-.] W + )*. W + ([-.] W + )*
The regular expression matching the URL:Http: // ([w-] +.) + [w-] + (/[W-./? % & =] *)?

(1) Application: 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 ;}

(2) Application: JavaScript does not have trim functions like VBScript, so we can use this expression to implement
String. Prototype. Trim = function ()
{
Return this. Replace (/(^ s *) | (S * $)/g, "");
}
(3) Application: use regular expressions to break down and convert IP addresses
Function ip2v (IP) // convert the IP address to the corresponding value
{
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 valid IP address !")
}
}
(4) Application: javascript programs that extract file names from URLs
S = "http://www.9499.net/page1.htm ";
S = S. Replace (/(. */) {0,} ([^.] +). */ig, "$2"); // page1.htm
(5) Application: use regular expressions to restrict text box input in a webpage form
You can only enter Chinese characters using regular expressions: onkeyup = "value ="/blog/value. replace (/["^ u4E00-u9FA5]/g,") "onbeforepaste =" clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ u4E00-u9FA5]/g ,"))"
Use regular expressions to limit that only the full-width characters can be entered: onkeyup = "value ="/blog/value. replace (/["^ uFF00-uFFFF]/g,") "onbeforepaste =" clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ uFF00-uFFFF]/g ,"))"
Use a regular expression to limit that only numbers can be entered: onkeyup = "value ="/blog/value. replace (/["^ d]/g,") "onbeforepaste =" clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ d]/g ,"))"
You can only enter numbers and English letters using regular expressions: onkeyup = "value ="/blog/value. replace (/[w]/g, ")" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ d]/g ,"

 

925736183
770769235
804136614
896318350 (panwl_83)
908175966 (Pwl.83@qq.com)
914563236 (pwl83)

925752673
908397954 (panwl83)
925747550
925749577
925740858
925753943
908140933

908554070 (Panwl.83@qq.com)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.