Regular Expression used to restrict passwords

Source: Internet
Author: User

Regular Expression used to restrict passwords

Only numbers can be entered in the text box, and only numbers can be entered in the text box. Disable pasting

Onpaste = "Return false;" onkeypress = "If (event. keycode <48 | event. keycode> 57) event. returnvalue = false ;"

Delete non-numeric Input

Onkeyup = "This. value = This. value. Replace (/[^/D *]/,'')"

Application Time:

<Input name = "sort" type = "text" id = "sort2" size = "3" maxlength = "3" onpaste = "Return false; "onkeypress =" If (event. keycode <48 | event. keycode> 57) event. returnvalue = false; "onkeyup =" this. value = This. value. replace (/[^/D *]/, '');">

Email Address Detection

VaR STRM = Document. myform. comail. Value // submit the text box of the mail address

VaR regm =/^ [a-zA-Z0-9 _-] + @ [a-zA-Z0-9 _-] + (/. [a-zA-Z0-9 _-] +) + $/; // validate the Regular Expression of mail, ^ [a-zA-Z0-9 _-]: must begin with a letter, underline, number,

If (! STRM. Match (regm) & STRM! = "")

{

Alert ("the email address format is incorrect or contains invalid characters! /N please check! ");

Document. myform. comail. Select ();

Return false;

}

Integer or decimal point: ^ [0-9] +/. {} [0-9] {} $

Only numbers are allowed: "^ [0-9] * $ ".

Only n digits can be entered: "^/d {n} $ ".

You can only enter at least N digits: "^/d {n,} $ ".

Only M ~ can be input ~ N-digit :. "^/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 })? $ ".

Only 1 ~ Positive number of three 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] + $ ".

You can only enter a string consisting of 26 uppercase letters: "^ [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] + $ ".

You can only enter a string consisting of digits, 26 English letters, or underscores: "^/W + $ ".

Verify the User Password: "^ [A-Za-Z]/W {5, 17} $" the correct format is: start with a letter, length is 6 ~ 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:" XXX-XXXXXXX "," XXXX-XXXXXXXX "," XXX-XXXXXXX "," XXX-XXXXXXXX "," xxxxxxx "and" 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 ".

Date Regular Expression and Detection

This is from yyyy-mm-dd hh: mm: Ss.

/^ (/D {4})/-(/d {2})/-(/d {2}) (/d {2 }) :(/d {2}) :(/d {2}) $ /;

This is from yyyy-mm-ddde.

/^ (/D {4})/-(/d {2})/-(/d {2}) $/

Function validatecndate (strvalue ){

VaR objregexp =/^/d {4} (/-| // |/.)/d {1, 2}/1/D {1, 2} $/

If (! Objregexp. Test (strvalue ))

Return false;

Else {

VaR arraydate = strvalue. Split (Regexp. $1 );

VaR intday = parseint (arraydate [2], 10 );

VaR intyear = parseint (arraydate [0], 10 );

VaR intmonth = parseint (arraydate [1], 10 );

If (intmonth> 12 | intmonth <1 ){

Return false;

}

VaR arraylookup = {'1': 31, '3': 31, '4': 30, '5': 31, '6': 30, '7': 31,

'8': 31, '9': 30, '10': 31, '11': 30, '12': 31}

If (arraylookup [parseint (arraydate [1])]! = NULL ){

If (intday <= arraylookup [parseint (arraydate [1])] & intday! = 0)

Return true;

}

If (intMonth-2 = 0 ){

VaR booleapyear = (intyear % 4 = 0 & (intyear % 100! = 0 | intyear % 400 = 0 ));

If (booleapyear & intday <= 29) | (! Booleapyear & intday <= 28) & intday! = 0)

Return true;

}

}

Return false;

}

 

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.