// 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 })? $/Mobile:/^ (\ D {2, 3} \) | (\ D {3 }\-))? 13 \ D {9} $/url:/^ http: \/[A-Za-z0-9] + \. [A-Za-z0-9] + [\/= \? % \-&_~ '@ [\] \': +!] * ([^ <> \ "\"]) * $/Idcard:/^ \ D {15} (\ D {2} [A-Za-z0-9])? $/QQ:/^ [1-9] \ D {} $/some special amount:/^ (\ D {} (, \ D {3 }) *) | (\ D + ))(\. \ D {2 })? $ // Description: In addition to the format "xxx xx, xxx XX, xxx.00", // provides various JS verification methods. trim () attribute string. prototype. trim = function () {return this. replace (/(^ \ s *) | (\ s * $)/g ,"");}
[Input type = "text" name = "str"]
[Input type = "button" value = "OK" onclick = ""] // write the JS verification function to be called in onclick.