Common JS verification REG and js verification reg
Good JS verification ~~~~~~~~~~~~~~~~~~~~~~~~~ Purpose: Verify the format of the IP address input: strIP: Return IP Address: true if verification is successful, otherwise false is returned; */function isIP (strIP) {if (isNull (strIP )) return false; var re =/^ (\ d + )\. (\ d + )\. (\ d + )\. (\ d +) $/g // The regular expression that matches the IP address if (re. test (strIP) {if (RegExp. $1 <256 & RegExp. $2 <256 & RegExp. $3 <256 & RegExp. $4 <256) return true;} return false;}/* purpose: Check whether the input string is null or all are spaces. Input: str returns: true if all are null, otherwise, false */function isNull (str) {if (str = ") return is returned. True; var regu = "^ [] + $"; var re = new RegExp (regu); return re. test (str);}/* purpose: Check whether the value of the input object complies with the integer format. Input: String input by str. Return: true if verification succeeds, otherwise, false */function isInteger (str) {var regu =/^ [-] {0, 1} [0-9] {1, }$/; return regu. test (str);}/* purpose: Check whether the entered mobile phone number is correct. Input: s: String. Return: true if the verification succeeds. Otherwise, false */function checkMobile (s) is returned) {var regu =/^ [1] [3] [0-9] {9} $/; var re = new RegExp (regu); if (re. test (s) {return tru E;} else {return false;}/* purpose: Check whether the input string conforms to the positive integer format. Input: s: String. return: true if it passes verification, otherwise, false */function isNumber (s) {var regu = "^ [0-9] + $"; var re = new RegExp (regu); if (s. search (re )! =-1) {return true;} else {return false;}/* purpose: Check whether the input string is in decimal number format. It can be a negative number. Input: s: String returns: if true is returned through verification, otherwise false */function isDecimal (str) {if (isInteger (str) return true; var re =/^ [-] {0, 1} (\ d +) [\.] + (\ d +) $/; if (re. test (str) {if (RegExp. $1 = 0 & RegExp. $2 = 0) return false; return true;} else {return false;}/* purpose: Check whether the value of the input object complies with the port number format input: return the string entered by str: if true is returned after verification, otherwise false */function isPo is returned. Rt (str) {return (isNumber (str) & str <65536);}/* purpose: Check whether the value of the input object complies with the input in E-Mail format: return the string entered by str: if true is returned after verification, otherwise false */function isEmail (str) is returned) {var myReg =/^ [-_ A-Za-z0-9] + @ ([_ A-Za-z0-9] + \.) + [A-Za-z0-9] {2, 3} $/; if (myReg. test (str) return true; return false;}/* purpose: Check whether the input string conforms to the value format defined as a positive number with decimal places. Up to three decimal places can be entered: s: string return: if true is returned after verification, otherwise false */function isMoney (s) {var regu = "^ [0-9] + [\.] is returned. [0-9] {0, 3} $ "; Var re = new RegExp (regu); if (re. test (s) {return true;} else {return false;}/* purpose: Check whether the input string is composed of letters, numbers, and underscores only. Input: s: string return: if true is returned after verification, otherwise false */function isNumberOr_Letter (s) is returned) {// determine whether it is a number or letter var regu = "^ [0-9a-zA-Z \ _] + $"; var re = new RegExp (regu); if (re. test (s) {return true;} else {return false;}/* purpose: Check whether the input string is composed of only English letters and numbers. Input: s: String returns: if true is returned after verification, otherwise false */function isNum is returned. BerOrLetter (s) {// determines whether it is a number or letter var regu = "^ [0-9a-zA-Z] + $"; var re = new RegExp (regu); if (re. test (s) {return true;} else {return false;}/* purpose: Check whether the input string is composed of only Chinese characters, letters, and numbers. Input: value: String returns: if true is returned after verification, false */function isChinaOrNumbOrLett (s) is returned) {// determine whether the component is a var regu = "^ [0-9a-zA-Z \ u4e00-\ u9fa5] + $"; var re = new RegExp (regu ); if (re. test (s) {return true;} else {return false;}/* purpose: Yes No: date input: date; fmt: Return in date Format: true if verification is successful; otherwise, false */function isDate (date, fmt) is returned) {if (fmt = null) fmt = "yyyyMMdd"; var yIndex = fmt. indexOf ("yyyy"); if (yIndex =-1) return false; var year = date. substring (yIndex, yIndex + 4); var mIndex = fmt. indexOf ("MM"); if (mIndex =-1) return false; var month = date. substring (mIndex, mIndex + 2); var dIndex = fmt. indexOf ("dd"); if (dIndex =-1) return false; var day = Date. substring (dIndex, dIndex + 2); if (! IsNumber (year) | year> "2100" | year <"1900") return false; if (! IsNumber (month) | month> "12" | month <"01") return false; if (day> getMaxDay (year, month) | day <"01 ") return false; return true;} function getMaxDay (year, month) {if (month = 4 | month = 6 | month = 9 | month = 11) return "30"; if (month = 2) if (year % 4 = 0 & year % 100! = 0 | year % 400 = 0) return "29"; else return "28"; return "31";}/* purpose: whether character 1 ends with string 2 input: str1: string; str2: contained string return: true if verified; otherwise false */function isLastMatch (str1, str2) {var index = str1.lastIndexOf (str2); if (str1.length = index + str2.length) return true; return false;}/* purpose: whether character 1 starts from string 2 input: str1: string; str2: string to be included: returns true if it passes verification; otherwise, returns false */function isFirstMatch (str1, str2) {var index = str1.inde XOf (str2); if (index = 0) return true; return false;}/* purpose: character 1 contains string 2 input: str1: string; str2: returns the contained string: returns true if it passes verification. Otherwise, false */function isMatch (str1, str2) {var index = str1.indexOf (str2) is returned ); if (index =-1) return false; return true;}/* purpose: Check whether the input start and end dates are correct. The rules are in the correct format for the two dates, end on schedule> = Start Date input: startDate: start date, string endDate: end on schedule, string return: true if verified, otherwise false */function checkTwoDate (startDate, endDate) {if (! IsDate (startDate) {alert ("Incorrect start date! "); Return false;} else if (! IsDate (endDate) {alert ("the end date is incorrect! "); Return false;} else if (startDate> endDate) {alert (" the start date cannot be greater than the end date! "); Return false;} return true;}/* purpose: Check whether the input Email address format is correct. Input: strEmail: String: true if verification is successful, otherwise false */function checkEmail (strEmail) {// var emailReg =/^ [_ a-z0-9] + @ ([_ a-z0-9] + \.) + [a-z0-9] {2, 3} $/; var emailReg =/^ [\ w-] + (\. [\ w-] +) * @ [\ w-] + (\. [\ w-] +) + $/; if (emailReg. test (strEmail) {return true;} else {alert ("the Email address format you entered is incorrect! "); Return false ;}}/* purpose: Check whether the entered phone number is in the correct format. Input: strPhone: String returns: true if the verification succeeds, otherwise, false */function checkPhone (strPhone) {var phoneRegWithArea =/^ [0] [1-9] {2, 3}-[0-9] {5, 10} $/; is returned /; var phoneRegNoArea =/^ [1-9] {1} [0-9] {5, 8} $/; var prompt = "the phone number you entered is incorrect! "If (strPhone. length> 9) {if (phoneRegWithArea. test (strPhone) {return true;} else {alert (prompt); return false ;}} else {if (phoneRegNoArea. test (strPhone) {return true;} else {alert (prompt); return false ;}}/ * purpose: Check the check box selected quantity input: checkboxID: String return: returns the number of checked items in the check box */function checkSelect (checkboxID) {var check = 0; var I = 0; if (document. all (checkboxID ). length> 0) {for (I = 0; I <d Ocument. all (checkboxID ). length; I ++) {if (document. all (checkboxID ). item (I ). checked) {check + = 1 ;}} else {if (document. all (checkboxID ). checked) check = 1;} return check;} function getTotalBytes (varField) {if (varField = null) return-1; var totalCount = 0; for (I = 0; I <varField. value. length; I ++) {if (varField. value. charCodeAt (I)> 127) totalCount + = 2; else totalCount ++;} return TotalCount;} function getFirstSelectedValue (checkboxID) {var value = null; var I = 0; if (document. all (checkboxID ). length> 0) {for (I = 0; I <document. all (checkboxID ). length; I ++) {if (document. all (checkboxID ). item (I ). checked) {value = document. all (checkboxID ). item (I ). value; break ;}}else {if (document. all (checkboxID ). checked) value = document. all (checkboxID ). value;} return value;} fun Ction getFirstSelectedIndex (checkboxID) {var value =-2; var I = 0; if (document. all (checkboxID ). length> 0) {for (I = 0; I <document. all (checkboxID ). length; I ++) {if (document. all (checkboxID ). item (I ). checked) {value = I; break ;}} else {if (document. all (checkboxID ). checked) value =-1;} return value;} function selectAll (checkboxID, status) {if (document. all (checkboxID) = null) return; If (document. all (checkboxID ). length> 0) {for (I = 0; I <document. all (checkboxID ). length; I ++) {document. all (checkboxID ). item (I ). checked = status ;}} else {document. all (checkboxID ). checked = status ;}} function selectInverse (checkboxID) {if (document. all (checkboxID) = null) return; if (document. all (checkboxID ). length> 0) {for (I = 0; I <document. all (checkboxID ). length; I ++) {document. a Ll (checkboxID). item (I). checked =! Document. all (checkboxID). item (I). checked ;}} else {document. all (checkboxID). checked =! Document. all (checkboxID). checked;} function checkDate (value) {if (value = '') return true; if (value. length! = 8 |! IsNumber (value) return false; var year = value. substring (2100); if (year> "1900" | year <"") return false; var month = value. substring (4, 6); if (month> "12" | month <"01") return false; var day = value. substring (6, 8); if (day> getMaxDay (year, month) | day <"01") return false; return true;}/* purpose: check whether the input start and end dates are correct. The rule is that the two dates are in correct format or are empty and end dates> = Start Date input: startDate: start date, string endDate: end date, string return: If the verification succeeds, true is returned. Otherwise Returns false */function checkPeriod (startDate, endDate) {if (! CheckDate (startDate) {alert ("Incorrect start date! "); Return false;} else if (! CheckDate (endDate) {alert ("the end date is incorrect! "); Return false;} else if (startDate> endDate) {alert (" the start date cannot be greater than the end date! "); Return false;} return true;}/* purpose: Check whether the securities code is entered correctly: secCode: The securities code returns: If the verification succeeds, true is returned, otherwise, false */function checkSecCode (secCode) {if (secCode. length! = 6) {alert ("the length of the securities code should be 6 characters"); return false;} if (! IsNumber (secCode) {alert ("The securities code can only contain numbers"); return false;} return true ;} /*************************************** * ************ function: cTrim (sInputString, iType) description: function parameters: iType: 1 = remove space on the left of the string 2 = remove space on the left of the string 0 = remove space on the left and right of the string return value: remove the space string ************************************ * **************/function cTrim (sInputString, iType) {var sTmpStr = ''; var I =-1; if (iType = 0 | iType = 1) {while (sTmpStr = '') {++ I; sTmpStr = sInputString. substr (I, 1);} sInputString = sInputString. substring (I);} if (iType = 0 | iType = 2) {sTmpStr = ''; I = sInputString. length; while (sTmpStr = '') {-- I; sTmpStr = sInputString. substr (I, 1);} sInputString = sInputString. substring (0, I + 1);} return sInputString ;}