Verification of JS Regular Expressions and JS Regular Expressions

Source: Internet
Author: User

Verification of JS Regular Expressions and JS Regular Expressions

// Determine whether the input content is empty function IsNull () {var str = document. getElementById ('str '). value. trim (); if (str. length = 0) {alert ('Sorry, the text box cannot be blank or blank! '); // Change the "text box" to the attribute name you want to verify!} // Judge whether the date type is type in YYYY-MM-DD format function IsDate () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {var reg =/^ (\ d {}) (-| \/) (\ d {}) \ 2 (\ d })/; var r = str. match (reg); if (r = null) alert ('Sorry, the date format you entered is incorrect! '); // Change "date" to the name of the property to be verified!} // Determine whether the date type is YYYY-MM-DD hh: mm: ss format type function IsDateTime () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {var reg =/^ (\ d {}) (-| \/) (\ d {}) \ 2 (\ d }) (\ d {1, 2}) :( \ d {1, 2}) :( \ d {1, 2}) $/; var r = str. match (reg); if (r = null) alert ('Sorry, the date format you entered is incorrect! '); // Change "date" to the name of the property to be verified!} // Determine whether the date type is hh: mm: ss type function IsTime () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ (20 | 21 | 22 | 23 | [0-1] \ d) \: [0-5] [0-9]) (\: [0-5] [0-9])? $/If (! Reg. test (str) {alert ("sorry, the date format you entered is incorrect! "); // Change" date "to the attribute name you want to verify! }}}// Determines whether the entered character is an English letter function IsLetter () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [a-zA-Z] + $/; if (! Reg. test (str) {alert ("sorry, the English letter format you entered is incorrect! "); // Change" English letter type "to the attribute name you want to verify! }}}// Determines whether the input character is an integer function IsInteger () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [-+]? \ D * $/; if (! Reg. test (str) {alert ("sorry, the format of the integer type you entered is incorrect! "); // Replace" Integer type "with the property name you want to verify! }}}// Determines whether the input character is double precision function IsDouble (val) {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [-\ +]? \ D + (\. \ d + )? $/; If (! Reg. test (str) {alert ("sorry, the format of the Double Precision type you entered is incorrect! "); // Replace" double-precision type "with the property name you want to verify!} // Determine whether the input character is: a-z, A-Z, 0-9 function IsString () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [a-zA-Z0-9 _] + $/; if (! Reg. test (str) {alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! }}}// Determine whether the input character is Chinese function IsChinese () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [\ u0391-\ uFFE5] + $/; if (! Reg. test (str) {alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! }}} // Determine whether the input EMAIL format is correct function IsEmail () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ \ w + ([-+.] \ w +) * @ \ w + ([-.] \ w + )*\. \ w + ([-.] \ w +) * $/; if (! Reg. test (str) {alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! }}} // Determine whether the entered zip code (only six digits can be entered) is correct function IsZIP () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ \ d {6} $/; if (! Reg. test (str) {alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! }}} // Judge whether the input number is greater than a specific number. function MaxValue () {var val = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [-+]? \ D * $/; if (! Reg. test (str) {// determine whether it is a numeric type if (val> parseInt ('000000') // "123" is the maximum value set by yourself {alert ('Sorry, the number you entered is out of the range '); // change "Number" to the attribute name you want to verify! }}} Phone:/^ (\ d {2, 3} \) | (\ d {3 }\-))? (\ (0 \ d {2, 3} \) | 0 \ d {2, 3 }-)? [1-9] \ d {6, 7} (\-\ d {1, 4 })? /; Var r = str. match (reg); if (r = null) alert ('Sorry, the date format you entered is incorrect! '); // Change "date" to the name of the property to be verified!} // Determine whether the date type is YYYY-MM-DD hh: mm: ss format type function IsDateTime () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {var reg =/^ (\ d {}) (-| \/) (\ d {}) \ 2 (\ d }) (\ d {1, 2}) :( \ d {1, 2}) :( \ d {1, 2}) $/; var r = str. match (reg); if (r = null) alert ('Sorry, the date format you entered is incorrect! '); // Change "date" to the name of the property to be verified!} // Determine whether the date type is hh: mm: ss type function IsTime () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ (20 | 21 | 22 | 23 | [0-1] \ d) \: [0-5] [0-9]) (\: [0-5] [0-9])? $/If (! Reg. test (str) {alert ("sorry, the date format you entered is incorrect! "); // Change" date "to the attribute name you want to verify! }}}// Determines whether the entered character is an English letter function IsLetter () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [a-zA-Z] + $/; if (! Reg. test (str) {alert ("sorry, the English letter format you entered is incorrect! "); // Change" English letter type "to the attribute name you want to verify! }}}// Determines whether the input character is an integer function IsInteger () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [-+]? \ D * $/; if (! Reg. test (str) {alert ("sorry, the format of the integer type you entered is incorrect! "); // Replace" Integer type "with the property name you want to verify! }}}// Determines whether the input character is double precision function IsDouble (val) {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [-\ +]? \ D + (\. \ d + )? $/; If (! Reg. test (str) {alert ("sorry, the format of the Double Precision type you entered is incorrect! "); // Replace" double-precision type "with the property name you want to verify!} // Determine whether the input character is: a-z, A-Z, 0-9 function IsString () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [a-zA-Z0-9 _] + $/; if (! Reg. test (str) {alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! }}}// Determine whether the input character is Chinese function IsChinese () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [\ u0391-\ uFFE5] + $/; if (! Reg. test (str) {alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! }}} // Determine whether the input EMAIL format is correct function IsEmail () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ \ w + ([-+.] \ w +) * @ \ w + ([-.] \ w + )*\. \ w + ([-.] \ w +) * $/; if (! Reg. test (str) {alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! }}} // Determine whether the entered zip code (only six digits can be entered) is correct function IsZIP () {var str = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ \ d {6} $/; if (! Reg. test (str) {alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! }}} // Judge whether the input number is greater than a specific number. function MaxValue () {var val = document. getElementById ('str '). value. trim (); if (str. length! = 0) {reg =/^ [-+]? \ D * $/; if (! Reg. test (str) {// determine whether it is a numeric type if (val> parseInt ('000000') // "123" is the maximum value set by yourself {alert ('Sorry, the number you entered is out of the range '); // change "Number" to the attribute name you want to verify! }}} Phone:/^ (\ d {2, 3} \) | (\ d {3 }\-))? (\ (0 \ d {2, 3} \) | 0 \ d {2, 3 }-)? [1-9] \ d {6, 7} (\-\ d {1, 4 })? /Mobile:/^ (\ d2, 3 \ d2, 3) | (\ d {3 }\-))? 13 \ d {9}/Url:/http: \/[A − Za − z0 − 9] + \. [A − Za − z0 − 9] + [\/= \? /Url:/http: \/[A − Za − z0 − 9] + \. [A − Za − z0 − 9] + [\/= \? /IdCard:/^ \ d {15} (\ d {2} [A-Za-z0-9])? /QQ:/[1−9] \ d4, 8/QQ:/[1−9] \ d4, 8/

A special amount:/^ (\ d {1, 3} (, \ d {3}) *) | (\ d +) (\. \ d {2 })? $/

// Note: In addition to the format "xxx xx, xxx xx, XXX.00", // provide the preceding JS verification methods. trim () attribute String. prototype. trim = function () {return this. replace (/(^ \ s *) | (\ s * $)/g ,"");}

Call:

<Input type = "text" name = "str"> <input type = "button" value = "OK" onClick = ""> // write the JS you want to call in onClick. verify the Function

The above is the verification of the JS regular expression introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave a message. The editor will reply to you in time!

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.