This article describes the detailed summary of the js verification form, which has some reference value and needs, you can refer to the good JS verification ~~~~~~~~~~~~~~~~~~~~~~~~~
Purpose: Verify the IP address format.
Input: strIP: IP Address
Return: If the verification succeeds, true is returned; 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
Return Value:
If all values are null, true is returned. Otherwise, false is returned.
*/ function isNull( str ){ if ( str == "" ) return true; var regu = "^[ ]+$"; var re = new RegExp(regu); return re.test(str); } /*
Purpose: Check whether the value of the input object conforms to the integer format.
Input: str string
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/ 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 Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/ function checkMobile( s ){ var regu =/^[1][3][0-9]{9}$/; var re = new RegExp(regu); if (re.test(s)) { return true; }else{ return false; } } /*
Purpose: Check whether the input string conforms to the positive integer format.
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/ 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
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/ 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 conforms to the port number format.
Input: str string
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/ function isPort( str ){ return (isNumber(str) && str<65536); } /*
Purpose: Check whether the value of the input object complies with the E-Mail format.
Input: str string
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/ function isEmail( str ){ 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 meets the amount format
The format is defined as a positive number with decimal places. A maximum of three decimal places can be entered.
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/ function isMoney( s ){ var regu = "^[0-9]+[\.][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 English letters, numbers, and underscores (_).
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/Function isNumberOr_Letter (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 consists of only English letters and numbers.
Input:
S: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/Function isNumberOrLetter (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 consists of only Chinese characters, letters, and numbers.
Input:
Value: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/Function isChinaOrNumbOrLett (s) {// judge whether it is composed of Chinese characters, letters, and numbers. var regu = "^ [0-9a-zA-Z \ u4e00-\ u9fa5] + $ "; var re = new RegExp (regu); if (re. test (s) {return true;} else {return false ;}}/*
Purpose: determine whether it is a date.
Input: date; fmt: date Format
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/ function isDate( date, fmt ) { 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: If the verification succeeds, true is returned; otherwise, false is returned.
*/ function isLastMatch(str1,str2) { var index = str1.lastIndexOf(str2); if(str1.length==index+str2.length) return true; return false; } /*
Purpose: whether character 1 starts with string 2
Input: str1: string; str2: contained string
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/ function isFirstMatch(str1,str2) { var index = str1.indexOf(str2); if(index==0) return true; return false; } /*
Purpose: character 1 is a string containing 2
Input: str1: string; str2: contained string
Return: If the verification succeeds, true is returned; otherwise, false is returned.
*/ function isMatch(str1,str2) { var index = str1.indexOf(str2); 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 date, string
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/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 entered Email address format is correct.
Input:
StrEmail: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/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 format is correct.
Input:
StrPhone: String
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/Function checkPhone (strPhone) {var phoneRegWithArea =/^ [0] [1-9] {2, 3}-[0-9] {5, 10} $ /; 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 number of selected check boxes.
Input:
CheckboxID: String
Return Value:
Returns the number of selected items in the check box.
*/ function checkSelect( checkboxID ) { var check = 0; var i=0; if( document.all(checkboxID).length > 0 ) { for( i=0; 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
0 ){ for( i=0; i
0 ){ for( i=0; i
0 ) { for( i=0; i
"2100" || year< "1900") 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 rules are correct or empty.
And end date> = Start Date
Input:
StartDate: start date, string
EndDate: end date, string
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/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 correct
Input:
SecCode: securities code
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/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: String space-removing Function
Parameters: iType: 1 = remove the space on the left of the string
2 = remove the space on the left of the string
0 = remove spaces on the left and right of the string
Return value: a string that removes spaces.
**************************************** ************/
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; } /*
The above is a detailed summary of the js verification form. For more information, see the PHP Chinese website (www.php1.cn )!