Data Validity verification 2.1. // determine whether the input content is null function IsNull () {1. var str = document. getElementById ('str '). value. trim (); 2. if (str. length = 0) {3. alert ('Sorry, the text box cannot be blank or blank! '); // Change the "text box" to the attribute name you want to verify! 1 .} 2 .} 3. 4. // determine whether the date type is the type function IsDate () in YYYY-MM-DD format {1. var str = document. getElementById ('str '). value. trim (); 2. if (str. length! = 0) {3. var reg =/^ (\ d {}) (-| \/) (\ d {}) \ 2 (\ d {}) $/; 4. var r = str. match (reg); 5. if (r = null) 6. alert ('Sorry, the date format you entered is incorrect! '); // Change "date" to the name of the property to be verified! 1 .} 2 .} 3. 4. // judge whether the date type is YYYY-MM-DD hh: mm: ss format type function IsDateTime () {1. var str = document. getElementById ('str '). value. trim (); 2. if (str. length! = 0) {3. var reg =/^ (\ d {}) (-| \/) (\ d {}) \ 2 (\ d }) (\ d {1, 2}) :( \ d {1, 2}) :( \ d {1, 2}) $/; 4. var r = str. match (reg); 5. if (r = null) 6. alert ('Sorry, the date format you entered is incorrect! '); // Change "date" to the name of the property to be verified! 1 .} 2 .} 3. 4. // determine whether the date type is hh: mm: ss type function IsTime () 1. {2. var str = document. getElementById ('str '). value. trim (); 3. if (str. length! = 0) {4. reg =/^ (20 | 21 | 22 | 23 | [0-1] \ d) \: [0-5] [0-9]) (\: [0-5] [0-9])? $/5. if (! Reg. test (str) {6. alert ("sorry, the date format you entered is incorrect! "); // Change" date "to the attribute name you want to verify! 1 .} 2 .} 3 .} 4. 5. // determine whether the entered character is an English letter function IsLetter () 1. {2. var str = document. getElementById ('str '). value. trim (); 3. if (str. length! = 0) {4. reg =/^ [a-zA-Z] + $/; 5. if (! Reg. test (str) {6. alert ("sorry, the English letter format you entered is incorrect! "); // Change" English letter type "to the attribute name you want to verify! 1.1.1 .} 2 .} 3 .} 4. 5. // determine whether the input character is an integer function IsInteger () 1. {2. var str = document. getElementById ('str '). value. trim (); 3. if (str. length! = 0) {4. reg =/^ [-+]? \ D * $/; 5. if (! Reg. test (str) {6. alert ("sorry, the format of the integer type you entered is incorrect! "); // Replace" Integer type "with the property name you want to verify! 1 .} 2 .} 3 .} 4. 5. // determine whether the input character is double-precision function IsDouble (val) 1. {2. var str = document. getElementById ('str '). value. trim (); 3. if (str. length! = 0) {4. reg =/^ [-\ +]? \ D + (\. \ d + )? $/; 5. if (! Reg. test (str) {6. 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! 1.1. 2 .} 3 .} 4 .} 5. 6. 7. // determine whether the input character is: a-z, A-Z, 0-9 function IsString () 1. {2. var str = document. getElementById ('str '). value. trim (); 3. if (str. length! = 0) {4. reg =/^ [a-zA-Z0-9 _] + $/; 5. if (! Reg. test (str) {6. alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! 1.1. 2 .} 3 .} 4 .} 5. 6. // determine whether the input character is Chinese function IsChinese () 1. {2. var str = document. getElementById ('str '). value. trim (); 3. if (str. length! = 0) {4. reg =/^ [\ u0391-\ uFFE5] + $/; 5. if (! Reg. test (str) {6. alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! 1.1. 2 .} 3 .} 4 .} 5. 6. // determine whether the input EMAIL format is correct. function IsEmail () 1. {2. var str = document. getElementById ('str '). value. trim (); 3. if (str. length! = 0) {4. reg =/^ \ w + ([-+.] \ w +) * @ \ w + ([-.] \ w + )*\. \ w + ([-.] \ w +) * $/; 5. if (! Reg. test (str) {6. alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! 1.1. 2 .} 3 .} 4 .} 5. 6. // determine whether the entered zip code (only six digits can be entered) is correct. function IsZIP () 1. {2. var str = document. getElementById ('str '). value. trim (); 3. if (str. length! = 0) {4. reg =/^ \ d {6} $/; 5. if (! Reg. test (str) {6. alert ("sorry, the format of the string type you entered is incorrect! "); // Replace" string type "with the property name you want to verify! 1.1. 2 .} 3 .} 4 .} 5. 6. // judge whether the input number is greater than a specific number. function MaxValue () 1. {2. var val = document. getElementById ('str '). value. trim (); 3. if (str. length! = 0) {4. reg =/^ [-+]? \ D * $/; 5. if (! Reg. test (str) {// determines whether it is a numeric type if (val> parseInt ('000000') // "123" indicates the maximum value set by yourself {2. alert ('Sorry, the number you entered is out of range '); // change "Number" to the attribute name you want to verify! 1 .} 2 .} 3 .} 4 .} 5. 6. another way of writing: The following is to verify when the form is submitted, and add an attribute onsubmit = "return on_submit ()" similar to this:
If return on_submit () returns true, it is submitted. If return is false, It is not submitted.
1.