2.1.//determines 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 empty or blank! '); /Please change the text box to the name of the property you need to verify! 1.} 2.} 3.4.//determines whether the date type is YYYY-MM-DD format type function IsDate () {1. var str = document.getElementById (' str '). Value.trim (); 2. if (str.length!=0) {3. var reg =/^ (\d{1,4}) (-|\/) (\d{1,2}) \2 (\d{1,2}) $/; 4. var r = Str.match (reg); 5. if (r==null) 6. Alert (' Sorry, the date you entered is not in the correct format! '); Please change "date" to the name of the property you need to verify! 1.} 2.} 3.4.//determines 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{1,4}) (-|\/) (\d{1,2}) \2 (\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2}) $/; 4. var r = Str.match (reg); 5. if (r==null) 6. Alert (' Sorry, the date you entered is not in the correct format! '); Please change "date" to the name of the property you need to verify! 1.} 2.} 3.4.type function Istime () 1 that determines whether the date type is in the HH:MM:SS format. {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 you entered is not in the correct format!"); /Please change the "date" to the name of the property you need to verify! 1.} 2. } 3.} 4.5.//determines whether the character entered is the 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 type you typed is not properly formatted!"); /Please change the "English letter type" to the name of the property you need to verify! 1.1.1.} 2. } 3.} 4.5.//determines whether the character entered 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 integer type you entered is not formatted correctly!"); /Please replace the "integer type" with the name of the property you want to verify! 1. } 2. } 3.} 4.5.//determines whether the character entered is a 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 double type you entered is not in the correct format!"); /Please replace "double type" with the name of the property you want to verify! 1.1.2. } 3. } 4.} 5.6. 7.//determines whether the character entered 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, you typed the string type incorrectly!"); /Please replace "string type" with the name of the property you want to verify! 1.1.2. } 3. } 4.} 5.6.//determines whether the character entered 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, you entered theString type is not properly formatted! "); /Please replace "string type" with the name of the property you want to verify! 1.1.2. } 3. } 4.} 5.6.//determine if 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, you typed the string type incorrectly!"); /Please replace "string type" with the name of the property you want to verify! 1.1.2. } 3. } 4.} 5.6.//determine if the input ZIP code (six-bit only) 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, you typed the string type incorrectly!"); /Please replace "string type" with the name of the property you want to verify! 1.1.2. } 3. } 4.} 5.6.//determines that the number entered is not 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 the number type if (Val>parseint (' 123 '))//"123" sets the maximum value for itself {2. Alert (' Sorry, the number you entered is out of range ');//Please change "number" to the name of the property you want to verify! 1.} 2. } 3. } 4.} 5.6. Another way of writing: The following is the validation when the form form is submitted, plus a property onsubmit= "return On_submit ()" Similar to this
Common Javascrip page validation (GO)