Common functions of JSCommon2 /*
-------------------------------------------------------------------------------
File Name: check. js
Note: JavaScript scripts are used to check the input data of the webpage submission form.
Version: 1.0
*/
/*
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: 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 ;}/*
-------------------------------------------------------------------------------
(JavaScript script to verify the data entry in the form begin)
-------------------------------------------------------------------------------
*/Function checkForm (objFrm) {var len = 0; len = objFrm. elements. length; var I = 0; var objCheck; // text box for (I = 0; I <len; I ++) {objCheck = objFrm. elements [I]; if (objCheck. type = "text "&&! F_checkTextValid (objCheck) {return false ;}// drop-down box for (I = 0; I <len; I ++) {objCheck = objFrm. elements [I]; if (objCheck. type = "select-one "&&! F_checkSelectValid (objCheck) {return false ;}// if (f_checkStartAndEndDate (objFrm) = false) return false; return true;} function f_checkSelectValid (obj) {// alert ("check select"); if (obj. options. length <= 0) {alert ("no data in the drop-down list! "); Return false;} return true;} function f_checkStartAndEndDate (frm) {var len = frm. elements. length; if (len = null & len = 0) return true; var I = 0; var temp; var objCheck; var objStartDate; var objEndDate; // alert ("start date period check"); try {for (I = 0; I <len; I ++) {objCheck = frm. elements [I]; temp = objCheck. name; if (temp. indexOf ("startDate")> 0 | temp. indexOf ("beginDate")> 0) objStartD Ate = objCheck; if (temp. indexOf ("endDate")> 0) objEndDate = objCheck;} // alert (objStartDate. value); // alert (objEndDate. value); if (objStartDate. value = null | objStartDate. value = "" | objStartDate. value = null | objStartDate. value = "") {return true;} return checkTwoDate (objStartDate. value, objEndDate. value); // alert ("end date period check");} catch (E) {} return true;} function f_checkTextV Alid (obj) {// cannot be empty if (obj. getAttribute ("isNeed ")! = Null) {if (f_isNotNull (obj) = false) return false;} // The length cannot exceed if (obj. getAttribute ("maxlength ")! = Null) {if (f_checkLength (obj) = false) return false;} var checkType = ""; checkType = obj. getAttribute ("checkType"); if (checkType = null | checkType = "") return true; // if (checkType. indexOf ("number")> = 0) {if (f_isNumber (obj) = false) return false; if (f_checkNumType (obj, checkType) = false) return false ;} // if (checkType. indexOf ("positive")> = 0) {if (f_isNumber (obj) = false) return false; if (f _ IsPositive (obj) = false) return false; if (f_checkNumType (obj, checkType) = false) return false;} if (checkType. indexOf ("date")> = 0) {if (f_checkDate (obj) = false) return false;}/* switch (checkType) {case "number ": if (f_isNumber (obj) = false) return false; break; case "date": if (f_checkDate (obj) = false) return false; break; default :} */return true;} function f_isNotNull (obj) {if (obj. value = "") {F_alert (obj, "null value is not allowed! "); Return false;} return true;} function f_isNumber (obj) {if (isNaN (obj. value) {f_alert (obj, "value Type"); return false;} return true;} function f_checkDate (obj) {if (checkDate (obj. value) = false) {f_alert (obj, "it is not a legal Date Format! "); Return false;} return true;} function f_checkLength (obj) {if (getTotalBytes (obj)> Math. abs (obj. getAttribute ("maxlength") {f_alert (obj, "exceeds the length limit! "); Return false;} return true;} function f_alert (obj, alertStr) {var fielName = obj. getAttribute ("fieldName"); if (fielName = null) fielName = ""; alert (fielName + "\ n" + alertStr); obj. select (); obj. focus ();} function f_checkNumType (obj, numType) {// assume that the numeric type has been determined var strTemp; var numpric; var numLen; var strArr; var defalen Len = 19; var defaultpric = 5; try {if (numType = null | numType = "") r Eturn f_checkNumLenPrec (obj, defaultLen, defaultpric); if (numType. indexOf ("(") <0 | numType. indexOf (")") <0) return f_checkNumLenPrec (obj, defaultLen, defapripric); strTemp = numType. substr (numType. indexOf ("(") + 1, numType. indexOf (")")-numType. indexOf ("(")-1); if (strTemp = null | strTemp = ") return f_checkNumLenPrec (obj, defaultLen, defapripric); strArr = strTemp. split (","); numLen = Math. Abs (strArr [0]); numpric = Math. abs (strArr [1]); return f_checkNumLenPrec (obj, numLen, numpric);} catch (e) {alert ("in f_checkNumType =" + e); return f_checkNumLenPrec (obj, defaultLen, defapripric) ;}} function f_checkNumLenPrec (obj, len, pric) {var numReg; var value = obj. value; var strValueTemp, strInt, strDec; // alert (value + "====" + len + "====" + pric ); try {numReg =/[\-]/; strValueTemp = Value. replace (numReg, ""); strValueTemp = strValueTemp. replace (numReg, ""); // integer if (pric = 0) {numReg =/[\.] // alert (numReg. test (value); if (numReg. test (value) = true) {f_alert (obj, "the input must be of the integer type! "); Return false ;}} if (strValueTemp. indexOf (". ") <0) {// alert (" lennth = "+ strValueTemp); if (strValueTemp. length> (len-pric) {f_alert (obj, "the integer cannot exceed" + (len-pric) + "bit"); return false ;}} else {strInt = strValueTemp. substr (0, strValueTemp. indexOf (". "); // alert (" lennth = "+ strInt); if (strInt. length> (len-pric) {f_alert (obj, "the integer cannot exceed" + (len-pric) + "bit"); return false;} strDec = strVa LueTemp. substr (strValueTemp. indexOf (". ") + 1), strValueTemp. length); // alert ("pric =" + strDec); if (strDec. length> pric) {f_alert (obj, "the decimal point cannot exceed" + pric + "bit"); return false ;}return true ;} catch (e) {alert ("in f_checkNumLenPrec =" + e); return false ;}} function f_isPositive (obj) {var numReg =/[\-]/; if (numReg. test (obj. value) = true) {f_alert (obj, "must be a positive number! "); Return false;} return true;}/* function selectedCheckboxCount (form) function Description: Describes the optional counting parameters in Form: form: the specified form */function selectedCheckboxCount (form) {var length = 0; var I = 0; var count = 0; eles = form. elements; while (I
255) n = n + 1; return n }/*
Note:
1. Clear data in the table (0.0 and 0)
2. If no data exists in the cell, a space is automatically added.
3. Clear the checkbox of the blank row
Parameters:
Clearzero: whether to clear "0", "0.0", false not clear, true clear (true by default)
Tablename: name of the table to be cleared. The default value is sortTable.
*/Function clear_table (clearzero, tablename) {var tobject; if (tablename = null) tobject = gmobj ("sortTable"); else tobject = gmobj (tablename ); // if the table is not defined, if (tobject = null) return is not filtered; // if the function call parameter is null, the values 0 and 0.0 must be cleared. Otherwise, do not clear 0, 0.0. Var clear = (clearzero = null )? True: clearzero; // clear 0 and 0.0. Fill in the space var rows = tobject. rows; var j = 0; for (var I = 0; I
-------------------------------------------------------------------------------
Description: it is a JavaScript script that verifies the end Of the data item in the form.
-------------------------------------------------------------------------------
*/
/*
Purpose: Check whether the input string is in decimal number format. It can be a negative number (and meets the specified precision)
Input: str: String
L: Total digits
D: number of digits after the decimal point
Return Value:
If the verification succeeds, true is returned. Otherwise, false is returned.
*/ function isDecimal( str,l,d ){ if(isInteger(str)) { if (l==null) return true; if (str<0) l--; if (str.length<=l) return true; } var re = /^[-]{0,1}(\d+)[\.]+(\d+)$/; if (re.test(str)) { if (l==null) return true; if (d==null) d=0; if(RegExp.$1==0&&RegExp.$2==0) return false; if (RegExp.$1.length+RegExp.$2.length<=l && RegExp.$2.length<=d) return true; } return false; }