The examples in this article share with you the js verification framework, which is very practical for your reference. The specific content is as follows
1. Key methods and principles:
if (!eval(scriptCode)) in the function check(thisInput) method { return false; }2. Call example:
Copy the code code as follows:<input type="text" name="progress_payment_two" id="progress_payment_two" inputName="Progress payment 2 ratio (%)" validate="isNumeric;notNull" maxLength="350" value="" />
3. The isNumeric method and the notNull method will be automatically called during verification and the verification result information will be returned.
4. The source code of the verification framework is as follows
var ConfigValidateInfoType = "writeAlert"; //Support writeAlert and writePage,"writePage; writeAlert" var rmTempStatusIsAlert = false; var rmTempStatusIsFocus = false; var beginValidate = true; var set_All_Venus_Inputs_Default = true; String.prototype.trim = function() { return this.replace(/(^/s*)|(/s*$)/g, ""); } function checkAllForms(){ var checkResult = true; rmTempStatusIsAlert = false; rmTempStatusIsFocus = false; setAllVenusInputsDefault(); for (var i=0;i<document.forms.length;i++) { for (var j=0;j<document.forms[i].elements.length;j++) { var thisInput = document.forms[i].elements[j]; if ( thisInput.type!="hidden" && thisInput.type!="button" && !( thisInput.id.indexOf("TF_")>=0 && thisInput.id.indexOf("_TF")>0 ) &&thisInput.clientWidth!=0&&thisInput.style&&thisInput.style.display!='none'){ /* if(validateStr != null && validateStr.length > 0 ){ if(thisInput.tagName == 'TEXTAREA' && srcstr != '') { srcstr = replaceEnter(srcstr); if( thisInput.maxLength != null && thisInput.maxLength > 0 ){ if(thisInput.tagName == 'TEXTAREA' && srcstr != '') { srcstr = replaceEnter(srcstr); if( thisInput.maxLength != null && thisInput.maxLength > 0 ){ if (getStrLength(srcstr) > thisInput.maxLength){ writeValidateInfo(thisInput, "The input length at the focus is too long/n Please make sure the input length is within " +frm.maxLength+"); return false; } } } } */ if(thisInput.id&&thisInput.id.indexOf("supplier_id_ref_")!=-1&&document.getElementById("unionDiv")&&document.getElementById("unionDiv").style.display=="none"){ continue; } var rtValue = check(thisInput); if(checkResult && rtValue == false) { checkResult = false; break; } } } } return checkResult;} function check(thisInput) { var validateStr = thisInput.validate; if(validateStr == null) { return true; } var inputValue = thisInput.value; if ( beginValidate ) { var validateTemp = new Array(); validateTemp = validateStr.split(';'); for (var i=0;i<validateTemp.length;i++) { if(validateTemp[i].length == 0) { continue; } s = replaceSingleQuote(inputValue); try{ var scriptCode = "javascript:" + validateTemp[i]; //"javascript:" + validateTemp[i] + "('" + s + "', " + "thisInput)" if(validateTemp[i].indexOf("(") < 0 || validateTemp[i].indexOf(")") < 0) { scriptCode = "javascript:" + validateTemp[i] + "(s,thisInput)" } if (!eval(scriptCode)) { return false; } } catch(e) { alert("check function"+validateTemp[i]+"There is an exception, please check!" + "/n" + e.message ); return false; } } } return true;} function setAllVenusInputsDefault() { var frmslen = document.forms.length; for (var i=0;i<frmslen;i++) { var inslen = document.forms[i].elements.length; for (var j=0;j<inslen;j++) { var frm = document.forms[i].elements[j] if ( frm.type!="hidden" && frm.type!="button" && !( frm.id.indexOf("TF_")>=0 && frm.id.indexOf("_TF")>0 ) ){ if(frm.validate != null) { setVenusInputDefault(frm); writeValidateInfoAfterObject("", frm); } } } } return true;} function setVenusInputDefault(_frm) { _frm.style.borderStyle=""; _frm.style.borderColor=""; if( _frm.value != null ){ _frm.style.backgroundColor = ""; _frm.style.color = ""; }} function replaceEnter(_str) { /**Replace line-wind carriage return character**/ var str = _str; str = str.replace('/n','') str = str.replace('/r','') //alert(str.indexOf('/n')) if(str.indexOf('/n')!=-1 &&str.indexOf('/r')!=-1) { return replaceEnter(str); } else { return str; }} function replaceSingleQuote(_str) { /**Replace line-change carriage return character**/ var str = _str; str = str.replace('//','//u005C'); str = str.replace('/'','//u0027'); str = str.replace('(','//u0028'); str = str.replace('(','//u0028'); str = str.replace('(','//u0028'); str = str.replace('(','//u0028'); str = str.replace('(','//u0028'); str = str.replace('(','//u005C'); str = str.replace('//','//u0027'); str = str.replace('(','//u0028'); str = str str.replace(')','//u0029'); str = str.replace('/"','//u0022'); str = str.replace(';','//u0038'); //str = Jtrim(str); return str;} function isContains(_validateStr,_validator) { for (var i=0;i<_validateStr.length;i++) { if(_validateStr[i] == _validator) return true; } return false;} function writeValidateInfo(info, thisObj) { var inputName = The input of getInputNameFromObject(thisObj); info = inputName + " is incorrect! /n" + info; if(ConfigValidateInfoType.indexOf("writePage") >= 0) { writeValidateInfoAfterObject(info, thisObj); } if(ConfigValidateInfoType.indexOf("writeAlert") >= 0) { writeValidateInfoAlert(info, thisObj); } if(!rmTempStatusIsFocus) { setVenusInputError(thisObj); rmTempStatusIsFocus = true; }} function setVenusInputError(_frm) { try { //_frm.click(); // click will cause file upload error_frm.focus(); // Since SELCET does not support content selection and does not require content selection, special processing will prevent errors //Modification: Li Yue 2009-11-12 if(_frm.tagName!="SELECT"){ _frm.select(); } _frm.style.borderStyle="dashed"; _frm.style.borderColor="rgb(255,50,0)"; if( _frm.value != null && _frm.value.length > 0 ){ _frm.style.backgroundColor = "highlight"; _frm.style.color = "white"; } } catch(e) { alert(e.message); }} function writeValidateInfoAlert(info, thisObj) { if(!rmTempStatusIsAlert) { alert(info); rmTempStatusIsAlert = true; }} function writeValidateInfoAfterObject(info, thisObj) { //Write verification information var validateInfoObj = null; thisObj = getValidatePosition(thisObj); if(thisObj.nextSibling != null && thisObj.nextSibling.nextSibling != null && thisObj.nextSibling.tagName != null && thisObj.nextSibling.tagName.toUpperCase() == "FONT" && thisObj.nextSibling.nextSibling.tagName.toUpperCase() == "SPAN" && thisObj.nextSibling.nextSibling.className == "font_remain_prompt") { validateInfoObj = thisObj.nextSibling.nextSibling; } else { thisObj.insertAdjacentHTML("afterEnd", "<font></font><span class=font_remain_prompt></span>"); validateInfoObj = thisObj.nextSibling.nextSibling; } if(validateInfoObj.innerHTML.length > 0 || info.length > 0) { validateInfoObj.innerHTML = info; }} function getValidatePosition(thisObj) { if(thisObj.nextSibling != null && thisObj.nextSibling.className == "refButtonClass") { thisObj = getValidatePosition(thisObj.nextSibling); } else if(thisObj.nextSibling != null && thisObj.nextSibling.type == "hidden"){ thisObj = getValidatePosition(thisObj.nextSibling); } return thisObj;} function getInputNameFromObject(thisInput) { var inputName = thisInput.inputName ; if ( inputName == null || inputName.length == 0 ){ inputName = thisInput.name; if ( inputName == null || inputName.length == 0 ){ inputName = ""; } } return inputName;} function getStrLength(str){ var len = 0; for(var i=0;i<str.length;i++){ if (str.charCodeAt(i) > 255) len += 2; else len ++; } return len;} /************************************************************ranmin validate******************************************************************************************/function notNull(s, thisInput) { //Cannot be empty//Remove space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if (s.length == 0){ writeValidateInfo("cannot be empty or space!", thisInput); return false; } var s = Jtrim(s); if (s.length == 0){ writeValidateInfo("cannot be empty or space!", thisInput); return false; } return true;} function isJine(s, thisInput) { //cannot be empty var a=/^[0-9]*(/.[0-9]{1,2})?$/; if(!a.test(s)){ writeValidateInfo("There are illegal characters or the number of decimal places exceeds two digits", thisInput); return false; }else{ return true; }} function isMobile(s, thisInput) { //issue the mobile number: it must start with a number, except for the number, it can contain "-" //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } var obj=new Array() obj[0]="13"; obj[1]="14"; obj[2]="15"; obj[3]="18"; if(s != null ){ if(s.length != 11){ writeValidateInfo('Please enter a legal mobile number!', thisInput); return false; } var mob = 0; for ( var int = 0; int < obj.length; int++) { if(s.substring(0,2) == obj[int]){ mob = mob+1; } } if(mob == 0){ writeValidateInfo('Please enter a legal mobile number!', thisInput); return false; } } var patrn=/^[+]{0,1}(/d){1,3}[ ]?([-]?(((/d)|[ ]){1,12})+$/; if (!patrn.exec(s)) { writeValidateInfo('Please enter a legal mobile number!', thisInput); return false; } return true;} function isPostalCode(s, thisInput) { //It is the postal code//Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } var patrn=/^[a-zA-Z0-9 ]{3,12}$/; if (!patrn.exec(s)) { writeValidateInfo('Please enter the legal postal code!', thisInput); return false; } return true;} function isTel(s,thisInput) { //It is a normal phone number and fax number: it can start with "+", except for numbers, it can contain "-" //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } var patrn=/^[+]{0,1}(/d){1,3}[ ]?([-]?(((/d)|[ ]){1,12})+$/; if (!patrn.exec(s)) { writeValidateInfo('Please enter a legal phone number!',thisInput); return false } return true;} function isTelForFax(s,thisInput) { //It is a normal phone number and fax number: it can start with "+", except for the number, it can contain "-" //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } var patrn=/^(/d){3,4}[-](/d){7,8}$/; if (!patrn.exec(s)) { writeValidateInfo('Please enter a legal landline number, for example: 010-8888888!',thisInput); return false } return true;} function isFax(s,thisInput) { //It is a normal phone number and fax number: it can start with "+", except for the number, it can contain "-" //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } var patrn=/^(/d){3,4}[-](/d){7,8}$/; if (!patrn.exec(s)) { writeValidateInfo('Please enter a legal fax number, for example: 010-8888888!',thisInput); return false } return true;} function isChinese(s,thisInput) { //It's Chinese//Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } var ret = ischinese(s); if(!ret){ writeValidateInfo("Please enter Chinese", thisInput); return ret; } return ret;} function notChinese(s,thisInput) { //No Chinese//Remove space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } var ret = ischinese(s); if(ret){ writeValidateInfo("cannot enter Chinese", thisInput); return false; } return true; } function isNum(s,thisInput) { //It is a number//Remove space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } var digits = "0123456789"; var i = 0; var sLength = s.length; while ((i < sLength)) { var c = s.charAt(i); if (digits.indexOf(c) == -1){ writeValidateInfo ("Please enter the number!", thisInput); return false; } i++; } return true;} function isNumBigtoZero(s,thisInput) { //issue the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } var digits = "0123456789"; var i = 0; var sLength = s.length; while ((i < sLength)) { var c = s.charAt(i); if (digits.indexOf(c) == -1){ writeValidateInfo ("Please enter the number!", thisInput); return false; } i++; } try{ if(thisInput.value<=0){ writeValidateInfo ("The input value must be greater than zero!", thisInput); return false; } }catch(e){ } return true;}function isEmail(s,thisInput) { //issue the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } if (s.length > 100) { writeValidateInfo("email address length cannot exceed 100 bits!", thisInput); return false; } var regu = /^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$/; if (regu.exec(s)) { return true; } else { writeValidateInfo ("Please enter a valid and legal E-mail address!", thisInput); return false; }} function isIP() { //Yes IP var patrn=/^[0-9.]{1,20}$/; if (!patrn.exec(s)){ writeValidateInfo('Please enter the IP value!', thisInput); return false } return true;} /********************************************************************************************************************************************************************************************************************************************* Verify notNull******************************************************************/function notNullWithoutTrim(s,thisInput) { //Yes "" //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if ( s.length == 0){ writeValidateInfo('Please enter, this item cannot be empty!',thisInput); return false; } return true;} function isInteger(str,thisInput) { // is an integer// Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } str=str.trim(); if(str.length ==0){ return true; } var reg = "0123456789"; for (var i=0;i<str.length;i++){ var m = str.charAt(i); if (reg.indexOf(m) == -1) { writeValidateInfo('Please enter an integer!',thisInput); return false; } } return true; } function isNormalStrOnWeb(s,thisInput) { //It is a normal character (non-html tag) if (s.substring(0,1) == "<" || s.substring(0,1) == "//" || s.substring(0,1) == ""){ writeValidateInfo("The focus cannot start with <or////" ,thisInput); return false; } if (!HoldCode(s)){ writeValidateInfo("The full-width cannot be entered at the focus/"・/"//"―/"//"―/"//"―/"//"―/"//"―/"//"―/"//"―/"//"―/" character,thisInput); return false; } if (s.trim().length > 0){ if (s.indexOf("/"") > -1){ writeValidateInfo("Double quotes cannot be entered at the focus!!",thisInput); return false; } if (s.indexOf("/'") > -1){ writeValidateInfo("Single quotes cannot be entered at the focus",thisInput); return false; } if (s.indexOf("//") > -1){ writeValidateInfo(""Cannot be entered at the focus",thisInput); return false; } } return true; } //Basic function list function Jtrim(str) { //De-space function var i = 0; var len = str.length; if ( str == "" ) return( str ); var j = len -1; var flagbegin = true; var flagend = true; while ( flagbegin == true && i< len) { if ( str.charAt(i) == " " ) { i=i+1; flagbegin=true; } else { flagbegin=false; } } while (flagend== true && j>=0) { if (str.charAt(j)==" ") { j=j-1; flagend=true; } else { flagend=false; } } if ( i > j ) return (""); var trimstr = str.substring(i,j+1); return trimstr;} function isNumber(s) { //Number judgment function s=s.trim(); if(s.length ==0){ return true; } var digits = "0123456789"; var i = 0; var sLength = s.length; while ((i < sLength)) { var c = s.charAt(i); if (digits.indexOf(c) == -1) { return false; } i++; } return true;} function ischinese(s) { //Judge whether the Chinese function var ret=true; for(var i=0;i<s.length;i++) ret=ret && (s.charCodeAt(i)>=10000); return ret;} /************************************************************************************************************************Venus Web JavaScript Code:HTC General form inspection (being perfected)*********************************************************************/function HoldCode(str){ for(var i=0;i<str.length;i++){ if (str.charCodeAt(i) == 8212 || str.charCodeAt(i) == 183){ return false; } } return true;} function validateForm(current_form) { for (var i=0;i<current_form.length;i++){ if (current_form[i].type =="text" || current_form[i].type == "radio"){ if (current_form[i].value.substring(0,1) == "<" || current_form[i].value.substring(0,1) == "/>" || current_form[i].value.substring(0,1) == ""){ alert("The focus cannot start with <or/> or space"); current_form[i].focus(); current_form[i].select(); return false; } if (getStrLength(current_form[i].value) > current_form[i].maxLength){ alert("The input length is too long at the focus/n Please make sure that the input length is within " +current_form[i].maxLength+"); current_form[i].focus(); current_form[i].select(); return false; } if (!HoldCode(current_form[i].value)){ alert("The full-width cannot be entered at the focus/"・/"//"―/"//"―/"//"―/"//"―/"―/"//"―/")); current_form[i].focus(); current_form[i].select(); return false; } if (!is_empty(current_form[i].value)){ if (current_form[i].name == "scriptDefine"){ return true; } if (current_form[i].value.indexOf("/"") > -1){ alert("Double quotes cannot be entered at focus"); current_form[i].focus(); current_form[i].select(); return false; } } } } return true;} function checkNumber(s, inputName) { try{ //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } var thisObj = event.srcElement; var maxLength = thisObj.integerDigits; var scale = thisObj.decimalDigits; return checkNumberImpl(s, maxLength, scale); }catch(e){ }} function checkNumberImpl(s, maxLength, scale) { //Check the running mileage, decimal, integer part at most 10-2 if(s == "") { return true; } if(scale == undefined) { scale = 0; } if(maxLength == undefined) { maxLength = 38; } if(!isFloatNumber(s)) { return false; } if(s.indexOf(".") >0) { if(s.indexOf(".") <= maxLength && (Math.round(s*(pow(10,scale))))<(pow(10,(maxLength + scale))))) { return true; } else { alert("The integer part is maximum" + (maxLength - scale) + "bits!"); return false; } } else { if(s.length <= maxLength) { return true; } else { alert("The integer part is maximum" + maxLength + "bits!!"); return false; } }} function isFloatNumber(s,inputName) { //Judge whether //Remove space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } var digits = "0123456789."; var i = 0; var sLength = s.trim().length; while ((i < sLength)) { var c = s.charAt(i); if (digits.indexOf(c) == -1){ writeValidateInfo("Please enter a valid number!", inputName); return false; } i++; } if(s.indexOf(".") != s.lastIndexOf(".")) { alert("The decimal point is incorrect, please enter a valid number!"); return false; } else { return true; }} function isSearch(s,thisInput) { //Cannot enter illegal characters if(s.length == 0 ) return true; var patrn=/^[^`~!@#$%^&*()+=|///][/]/{/}:;'/,.<>/?]{1}[^`~!@$%^&()+=|///][/]/{/}:;'/,.<>?]{0,5000}$/; var patrn2 = /[^/{/|/.//,<>"'_}/]/; if (!patrn.exec(s) || !patrn2.exec(s)){ writeValidateInfo('The input contains illegal characters, please re-enter!',thisInput); return false; } return true ;} //=====================================================================================================================/** * Verify the number (positive integer or number containing decimal). */function isNumeric(value, thisInput) { //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } value=value.trim(); if(value.length ==0){ return true; } var reg = /^/d+(/./d+)?$/; if (!reg.test(value)) { writeValidateInfo ("Please enter a positive integer or a decimal!", thisInput); return false; } return true;} /** * Verify the number (positive integer). */function checkInt(value, thisInput) { //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } value=value.trim(); if(value.length ==0){ return true; } var reg = /^[0-9]/d*$/; if (!reg.test(value)) { writeValidateInfo ("Please enter a positive integer!", thisInput); return false; } return true;}/** * Verify number (the maximum integer digit is 10 digits, and can be taken with decimals) */function validateNumericAndLength(value, thisInput) { //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } value=value.trim(); if(value.length ==0){ return true; } var reg = /^/d{1,10}(/./d+)?$/; if (!reg.test(value)) { writeValidateInfo ("Please enter a positive integer or a decimal (the integer digit can only have 10 digits)!", thisInput); return false; } return true;} /** * Verify number(18,2) */function isNum18p2(value, thisInput) { //Remove space try{ thisInput.value=thisInput.value.trim(); }catch(e){} value=value.trim(); if(value.length ==0){ return true; } var reg = /^(-)?/d{1,16}(/./d{1,2})?$/; if (!reg.test(value)) { writeValidateInfo ("Please enter a number (up to 16 integer digits, maximum 2 decimal places)!", thisInput); return false; } return true;} /** * Verify number(18,4) */function isNum18p4(value, thisInput) { //Remove space try{ thisInput.value=thisInput.value.trim(); }catch(e){} value=value.trim(); if(value.length ==0){ return true; } var reg = /^(-)?/d{1,14}(/./d{1,4})?$/; if (!reg.test(value)) { writeValidateInfo ("Please enter a number (up to 14 integer digits, up to 4 decimal digits)!", thisInput); return false; } return true;} /** * Verify number(5,2) */function isNum5p2(value, thisInput) { //Remove space try{ thisInput.value=thisInput.value.trim(); }catch(e){} value=value.trim(); if(value.length ==0){ return true; } var reg = /^(-)?/d{1,3}(/./d{1,2})?$/; if (!reg.test(value)) { writeValidateInfo ("Please enter a number (up to 3 integer digits, maximum to 2 decimal places)!", thisInput); return false; } return true;} /** * Verify Email. */function checkEmail(value, thisInput) { //Remove space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } value=value.trim(); if(value.length ==0){ return true; } var reg = /^/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*$/; if (!reg.test(value)) { writeValidateInfo ("Please enter the correct email address!", thisInput); return false; } return true;} /** * Verify the ID card (15-bit or 18-bit ID card). */function checkIdCard(value, thisInput) { //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } value=value.trim(); if(value.length ==0){ return true; } var reg = /^/d{15}(/d{2}[A-Za-z0-9])?$/; if (!reg.test(value)) { writeValidateInfo ("Please enter the correct ID number!", thisInput); return false; } return true;} /** * Verify the postal code. */function checkPostCode(value, thisInput) { //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } value=value.trim(); if(value.length ==0){ return true; } var reg = /^[0-9]/d{5}$/; if (!reg.test(value)) { writeValidateInfo ("Please enter the correct postal code!", thisInput); return false; } return true;} /** * Verify whether it is a Chinese character. */function checkChinese(value, thisInput) { //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } value=value.trim(); if(value.length ==0){ return true; } var reg = /^[/u0391-/uFFE5]+$/; if (!reg.test(value)) { writeValidateInfo ("Please enter Chinese characters!", thisInput); return false; } return true;} /** * Verify whether it is an illegal character. */function checkInvalidString(value, thisInput) { var reg = /^[^`~!@#$%^&*()+=|///][/]/{/}:;'/,.<>/?]*$/; if (!reg.exec(value)) { writeValidateInfo ("The entered character contains special characters, please re-enter!", thisInput); return false; } return true; } function checkMoney(s, inputName) { //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } s=s.trim(); if(s.length ==0){ return true; } if(s==""){ writeValidateInfo("Amount cannot be empty!", inputName); return false; } if(isFloatNumber(s,inputName)==false){ writeValidateInfo("Illegal amount value!", inputName); return false; } var maxLength = 10; var scale =2; return checkNumberImpl(s, maxLength, scale,inputName);} /** * Check whether the score is 0-100 */function isAdultAge(str,thisInput) { // is an integer//Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } str=str.trim(); if(str.length ==0){ return true; } if(parseInt(str)<0 || parseInt(str)>100){ writeValidateInfo('Please enter a legal score (between 0--100)!',thisInput); return false; } return true;} /** * Level 6 intensity settings (number, uppercase, lowercase letters, special characters, length >=6, length >=10) * If the password is empty, return 0 */function pwdStrength(pwd) { var sum = [0, 0, 0]; for (var i=0; i<pwd.length; i++) { var c = pwd.charCodeAt(i); if (c >=48 && c <=57) //number sum[0] = 1; else if (c >=65 && c <=90) //Uppercase sum[1] = 1; else if (c >=97 && c <=122) //Lowercase sum[1] = 1; else //Special character sum[2] = 1; } var level = sum[0] + sum[1] + sum[2] ; if (pwd.length >= 8) level++; return level;}function isBiggerZero(value, thisInput) { //Already a number, then must be greater than 0 if(thisInput.value<=0){ writeValidateInfo('Please enter a number greater than zero!',thisInput); return false; } return true;} function isNonnegative(value, thisInput) { if(thisInput.value<0){ writeValidateInfo('Please enter a non-negative number!',thisInput); return false; } return true;} /** * Verify number(20,6) */function isNum20p6(value, thisInput) { //Remove space try{ thisInput.value=thisInput.value.trim(); }catch(e){} value=value.trim(); if(value.length ==0){ return true; } var reg = /^(-)?/d{1,14}(/./d{1,6})?$/; if (!reg.test(value)) { writeValidateInfo ("Please enter a number (the maximum of 14 integer digits and the maximum of 6 decimal digits)!", thisInput); return false; } return isBiggerZero(value, thisInput);} /** * Verify the number (18,6) */function isNum18p6(value, thisInput) { //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){} value=value.trim(); if(value.length ==0){ return true; } var reg = /^(-)?/d{1,12}(/./d{1,6})?$/; if (!reg.test(value)) { writeValidateInfo ("Please enter a number (the maximum of 12 integer digits and the maximum of 6 decimal digits)!", thisInput); return false; } return isBiggerZero(value, thisInput);} function isNonnegative20p6(value, thisInput) { //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){} value=value.trim(); if(value.length ==0){ return true; } var reg = /^(-)?/d{1,14}(/./d{1,6})?$/; if (!reg.test(value)) { writeValidateInfo ("Please enter a number (the maximum of 14 integer digits and the maximum of 6 decimal digits)!", thisInput); return false; } return isNonnegative(value, thisInput);} /** * Verify number(20,4) */function isNum20p4(value, thisInput) { //Remove space try{ thisInput.value=thisInput.value.trim(); }catch(e){} value=value.trim(); if(value.length ==0){ return true; } var reg = /^(-)?/d{1,16}(/./d{1,4})?$/; if (!reg.test(value)) { writeValidateInfo ("Please enter a number (the maximum of 16 integer digits and the maximum of 4 decimal places)!", thisInput); return false; } return isBiggerZero(value, thisInput);} /** * The amount of a single batch of margin entered by the supplier can only be a positive integer and can only be accurate to hundreds of digits*/function isDPCBZJ(value, thisInput) { //Remove the space try{ thisInput.value=thisInput.value.trim(); }catch(e){ } value=value.trim(); if(value.length ==0){ return true; } var reg = /^[1-9]/d*00$/; if (!reg.test(value)) { writeValidateInfo ("Please enter the correct margin amount!", thisInput); return false; } return true;} //Judgement that the starting year of the report tender year cannot be greater than the end year function validateYear(startYear,endYear,flag) { if(startYear > endYear){ if(flag==1){ alert("The starting month cannot be greater than the end month"); return false; }else{ alert("The starting year of the bidding cannot be greater than the end year"); return false; } } return true;}The above is all about this article, I hope it will be helpful to everyone's learning.