Regular Expression Summary

Source: Internet
Author: User
Tags character classes

I. Regular telephone number

Http://s.click.taobao.com/t_8? E = 7hz5x % 2bozdswsvvyc5jts79au1q % 3d % 3d & P = mm_24156262_0_0

$ (). Ready (function (){

$ ("# Btnphone"). BIND ("click", function (){

JavascriptCode

VaR A =/^ (0 [0-9] {2, 3 }\-)? ([2-9] [0-9] {6, 7}) + (\-[0-9] {1, 4 })? $ | (^ (13 [0-9] | 15 [0 | 3 | 6 | 7 | 8 | 9] | 18 [8 | 9]) \ D {8 }$ )/;
VaR T1 = $ ("phone"). value;
If (! A. Test (T1 ))
{
Alert ("enter the correct phone number, \ n For example: 0591-6379256, 15005059587 ");
Return false;
}

});

Jquery code

VaR useremail = $ ("input [name = 'usermail']"). Val (); // obtain the value based on the tag input.
VaR userphone = $ ("input [name = 'userphone']"). Val ();
VaR tousername = $ ("input [name = 'tousername']"). Val ();
VaR touserphone = $ ("input [name = 'touserphone']"). Val ();

VaR emailtest =/^ [\ W \-\.] + @ [\ W \-\.] + (\. \ W +) + $ /;
VaR phonetest =/^ (1 [0-9]) \ D {9} $ /;

$ ("# Btnphone"). BIND ("click", function (){

If (! Emailtest. Test (useremail )){
Alert ("your email address is incorrect ");
Return false;
}

);

// Javascript script Protection Code

var IU, IUU, regarray = new array (
"@", "$", "%", "^ ","&","*", "(", ")", "+", "=", "|", "[", "]", "~ ", +
"! "," <","> "," Select "," from "," delete "," Count "," Update "," table "," truncate ", "ASC", "mid", "xp_cmdshell");

For (IU = 1; IU <= IUU; IU ++ ){
If (username. indexof (regarray [IU])>-1 ){
Alert ("My name cannot contain special characters ");
$ ("# Kuang01"). Focus ();
Return false
}
}

});

The jquery validation expression is summarized as follows:

1./^ \ D + $ // non-negative integer (positive integer + 0)

2./^ [0-9] * [1-9] [0-9] * $ // positive integer

3./^ (-\ D +) | (0 +) $ // non-positive integer (negative integer + 0)

4./^-[0-9] * [1-9] [0-9] * $ // negative integer

6. "^ -? \ D + $ "// integer

7. "^ \ D + (\. \ D + )? $ "// Non-negative floating point number (Positive floating point number + 0)

8. "^ ([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

9. "^ (-\ D + (\. \ D + )?) | (0 + (\. 0 + )?)) $ "// Non-Positive floating point number (negative floating point number + 0)

10. "^ (-([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

11. "^ (-? \ D +) (\. \ D + )? $ "// Floating point number

12. "^ [A-Za-Z] + $" // a string consisting of 26 letters

13. "^ [A-Z] + $" // a string consisting of 26 uppercase letters

14. "^ [A-Z] + $" // a string consisting of 26 lowercase letters

15. "^ [A-Za-z0-9] + $" // string consisting of digits and 26 letters

16. "^ \ W + $" // a string consisting of a number, 26 English letters, or underscores

17. "^ [\ W-] + (\. [\ W-] +) * @ [\ W-] + (\. [\ W-] +) + $ "// email address

18. "^ [A-Za-Z] +: // (\ W + (-\ W + )*)(\. (\ W + (-\ W + )*))*(\? \ S *)? $ "// URL

I. Verification

1. digit Verification

An integer of 1.1

/^ (-| \ + )? \ D + $/. Test (STR)

An integer greater than 0 in 1.2 (used for verification of sent IDs)

/^ \ D + $/. Test (STR)

Verification of a negative integer of 1.3

/^-\ D + $/. Test (STR)

2. Time

2.1 short time, such as (13:04:06)

Function Istime (STR)

{

VaR A = Str. Match (/^ (\ D {1, 2 })(:)? (\ D {1, 2}) \ 2 (\ D {1, 2}) $ /);

If (A = NULL) {alert ('input parameter is not in the timeformat '); Return false ;}

If (A [1]> 24 | A [3]> 60 | A [4]> 60)

{

Alert ("Time Format incorrect ");

Return false

}

Return true;

}

2.2 Short date, such)

Function strdatetime (STR)

{

VaR r = Str. match (/^ (\ D {}) (-| \/) (\ D {}) \ 2 (\ D {}) $ /);

If (r = NULL) return false;

VaR d = new date (R [1], R [3]-1, R [4]);

Return (D. getfullyear () = R [1] & (D. getmonth () + 1) = R [3] & D. getdate () = R [4]);

}

2.3 long time, for example (13:04:06)

Function strdatetime (STR)

{

VaR Reg =/^ (\ D {}) (-| \/) (\ D {}) \ 2 (\ D }) (\ D {1, 2}) :( \ D {1, 2}) :( \ D {1, 2}) $ /;

VaR r = Str. Match (REG );

If (r = NULL) return false;

VaR d = new date (R [1], R [3]-1, R [4], R [5], R [6], R [7]);

Return (D. getfullyear () = R [1] & (D. getmonth () + 1) = R [3] & D. getdate () = R [4] & D. gethours () = R [5] & D. getminutes () = R [6] & D. getseconds () = R [7]);

}

2.4 is only for years and months. Such as (2003-05, or 2003-5)

2.5 only hours and minutes, such)

3. Form class

3.1 The value of all forms cannot be blank

<Input ') = '') Alert (' cannot be blank! ') ">

The value of the 3.2 multi-row text box cannot be blank.

The value of the 3.3 Multi-line text box cannot exceed smaxstrleng

The value of the 3.4 multi-row text box cannot be less than that of smixstrleng

3.5 determine whether a single shard is selected.

3.6 check whether the check box is selected.

3.7 select all check boxes, select multiple, do not select all, select Inverse

3.8 determine the file type during File Upload

4. character classes

4.1 characters are all composed of letters A-Z or a A-Z

<Input error ') ">

The 4.2 character is composed of letters and numbers.

<Input error ') ">

The 4.3 judgment character consists of letters, numbers, underscores, and periods. It must start with an underscore or letter.

/^ ([A-Za-Z _] {1}) ([\ W] *) $/g. Test (STR)

4.4 string replacement function. Replace ();

5. Browser

5.1 determine the browser type

Window. Navigator. appname

5.2 judge the IE version

Window. Navigator. appversion

5.3 determine the client resolution

Window. Screen. height; window. Screen. width;

6. Integration class

6.1 email judgment.

Function Ismail (Mail)

{

Return (New Regexp (/^ \ W + (-\ W +) | (\. \ W +) * \ @ [A-Za-z0-9] + ((\. |-) [A-Za-z0-9] + )*\. [A-Za-z0-9] + $ /). test (Mail ));

}

6.2 mobile phone number verification

6.3 ID card verification

Function isidcardno (Num)

{

If (isnan (Num) {alert ("the input is not a number! "); Return false ;}

VaR Len = num. length, RE;

If (LEN = 15)

Re = new Regexp (/^ (\ D {6 })()? (\ D {2}) (\ D {2}) (\ D {2}) (\ D {3}) $ /);

Else if (LEN = 18)

Re = new Regexp (/^ (\ D {6 })()? (\ D {4}) (\ D {2}) (\ D {2}) (\ D {3}) (\ D) $ /);

Else {alert ("the number of digits entered is incorrect! "); Return false ;}

VaR A = num. Match (re );

If (! = NULL)

{

If (LEN = 15)

{

VaR d = new date ("19" + A [3] + "/" + A [4] + "/" + A [5]);

VaR B = D. getyear () = A [3] & (D. getmonth () + 1) = A [4] & D. getdate () = A [5];

}

Else

{

VaR d = new date (A [3] + "/" + A [4] + "/" + A [5]);

VaR B = D. getfullyear () = A [3] & (D. getmonth () + 1) = A [4] & D. getdate () = A [5];

}

If (! B) {alert ("InputID card numberThe birth date in "+ A [0] +" is incorrect! "); Return false ;}

}

Return true;

}

// Check whether it is composed of digits

Function isdigit (s)

{

VaR patrn =/^ [0-9] {1, 20} $ /;

If (! Patrn.exe C (s) return false

Return true

}

// Check Logon Name: You can enter only 5-20 strings starting with a letter, which can contain numbers, "_", and ".".

Function isregisterusername (s)

{

VaR patrn =/^ [A-Za-Z] {1} ([a-zA-Z0-9] | [. _]) {} $ /;

If (! Patrn.exe C (s) return false

Return true

}

// Check user name: only 1-30 strings starting with letters can be entered

Function istruename (s)

{

VaR patrn =/^ [A-Za-Z] {1, 30} $ /;

If (! Patrn.exe C (s) return false

Return true

}

// Password verification: only 6-20 letters, numbers, and underscores can be entered

Function ispasswd (s)

{

VaR patrn =/^ (\ W) {6, 20} $ /;

If (! Patrn.exe C (s) return false

Return true

}

// Verify the phone number and fax number. The phone number can start with "+" and contain "-" in addition to numbers.

Function istel (s)

{

// Var patrn =/^ [+] {0, 1} (\ D) {1, 3} []? ([-]? (\ D) {1, 12}) + $ /;

VaR patrn =/^ [+] {0, 1} (\ D) {1, 3} []? ([-]? (\ D) | []) {1, 12}) + $ /;

If (! Patrn.exe C (s) return false

Return true

}

// Verify the mobile phone number. It must start with a number and can contain "-" in addition to a number.

Function ismobil (s)

{

VaR patrn =/^ [+] {0, 1} (\ D) {1, 3} []? ([-]? (\ D) | []) {1, 12}) + $ /;

If (! Patrn.exe C (s) return false

Return true

}

// Verify the zip code

Function ispostalcode (s)

{

// Var patrn =/^ [a-zA-Z0-9] {3, 12} $ /;

VaR patrn =/^ [a-zA-Z0-9] {} $ /;

If (! Patrn.exe C (s) return false

Return true

}

// Verify the search keyword

Function issearch (s)

{

VaR patrn =/^ [^ '~! @ # $ % ^ & * () + = |\\] [\] \{\}:;\' \,. <>/?] {1} [^ '~! @ $ % ^ & () + =|\\] [\] \{\}:;\' \,. <>?] {0, 19} $ /;

If (! Patrn.exe C (s) return false

Return true

}

Function isip (s) // By zergling

{

VaR patrn =/^ [0-9.] {1, 20} $ /;

If (! Patrn.exe C (s) return false

Return true

}

// Extract the leading and trailing spaces of the string

VaR strstring = "AAAAA ";

Strstring = strstring. Replace (/(^ [\ s] *) | ([\ s] * $)/g ,"");

When regularexpression_r_r_rvalidator is used to verify the control, the verification function and its expression are described as follows:

Only numbers can be entered: "^ [0-9] * $"

Only n digits can be entered: "^ \ D {n} $"

Only a number of at least N digits can be entered: "^ \ 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 two decimal places can be entered.OfReal Number: "^ [0-9] + (. [0-9] {2 })? $"

Only 1 ~ 3 decimal placesOfReal Number: "^ [0-9] + (. [0-9] {1, 3 })? $"

You can only enter a non-zero value.OfInteger: "^ \ +? [1-9] [0-9] * $"

Only a non-zero negative integer can be entered: "^ \-[1-9] [0-9] * $"

Only 3 characters can be entered: "^. {3} $"

Only a string consisting of 26 English letters can be entered: "^ [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] + $"

Only strings consisting of digits and 26 English letters can be entered: "^ [A-Za-z0-9] + $"

Http://s.click.taobao.com/t_8? E = 7hz5x % 2bozdswsvvyc5jts79au1q % 3d % 3d & P = mm_24156262_0_0

Only strings consisting of digits, 26 English letters, or underscores can be entered: "^ \ W + $"

Verify the User Password: "^ [A-Za-Z] \ W {5, 17} $" correct format: it must start with a letter and have a length of 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 -./? % & =] *)? $ "

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.