麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > JavaScript > 正文

js驗證框架實現(xiàn)代碼分享

2019-11-20 10:00:32
字體:
供稿:網(wǎng)友

本文實例為大家分享了js驗證框架,很實用,供大家參考,具體內(nèi)容如下

1、關(guān)鍵方法和原理:

function check(thisInput) 方法中的 if (!eval(scriptCode)) {      return false;    }

2、調(diào)用示例:

復(fù)制代碼 代碼如下:
 <input type="text" class="text_field percentCheck" name="progress_payment_two" id="progress_payment_two" inputName="進(jìn)度款2比例(%)" validate="isNumeric;notNull" maxLength="350" value="" />

3、驗證時會自動調(diào)用:isNumeric 方法 和 notNull方法并返回驗證的結(jié)果信息。

4、驗證框架源碼如下

var ConfigValidateInfoType = "writeAlert"; //支持writeAlert和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 (getStrLength(srcstr) > thisInput.maxLength){                writeValidateInfo(thisInput, "焦點處輸入長度超長/n請確保輸入長度在" +frm.maxLength+"以內(nèi)");                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("校驗函數(shù)"+validateTemp[i]+"有異常,請檢查!" + "/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) {  /**替換換行回車字符**/  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) {  /**替換換行回車字符**/  var str = _str;  str = str.replace('//','//u005C');  str = str.replace('/'','//u0027');   str = str.replace('(','//u0028');  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 = getInputNameFromObject(thisObj);  info = inputName + "的輸入有誤!/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會導(dǎo)致文件上傳錯誤    _frm.focus();    //由于SELCET不支持內(nèi)容選擇,且不用內(nèi)容選擇,所以特殊處理,防止報錯    //修改:李岳 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) { //寫校驗信息  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) { //不能為空  //去掉空格  try{    thisInput.value=thisInput.value.trim();  }catch(e){       }  s=s.trim();     if (s.length == 0){    writeValidateInfo("不能為空或空格!", thisInput);    return false;  }   var s = Jtrim(s);    if ( s.length == 0){    writeValidateInfo("不能為空或空格!", thisInput);    return false;  }   return true;} function isJine(s, thisInput) { //不能為空   var a=/^[0-9]*(/.[0-9]{1,2})?$/;   if(!a.test(s)){     writeValidateInfo("有非法字符或者小數(shù)點位數(shù)超過兩位", thisInput);     return false;  }else{     return true;   }} function isMobile(s, thisInput) { //是手機(jī)號碼:必須以數(shù)字開頭,除數(shù)字外,可含有“-”   //去掉空格   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('請輸入合法的手機(jī)號碼!', 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('請輸入合法的手機(jī)號碼!', thisInput);      return false;    }  }  var patrn=/^[+]{0,1}(/d){1,3}[ ]?([-]?((/d)|[ ]){1,12})+$/;   if (!patrn.exec(s)) {    writeValidateInfo('請輸入合法的手機(jī)號碼!', thisInput);    return false;  }       return true;} function isPostalCode(s, thisInput) { //是郵政編碼  //去掉空格  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('請輸入合法的郵政編碼!', thisInput);    return false;  }   return true;}   function isTel(s,thisInput) { //是電話普通電話、傳真號碼:可以“+”開頭,除數(shù)字外,可含有“-”   //去掉空格  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('請輸入合法的電話號碼!',thisInput);    return false  }    return true;}  function isTelForFax(s,thisInput) { //是電話普通電話、傳真號碼:可以“+”開頭,除數(shù)字外,可含有“-”   //去掉空格  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('請輸入合法的座機(jī)號碼,例如:010-88888888!',thisInput);    return false  }    return true;}  function isFax(s,thisInput) { //是電話普通電話、傳真號碼:可以“+”開頭,除數(shù)字外,可含有“-”   //去掉空格  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('請輸入合法的傳真號碼,例如:010-88888888!',thisInput);    return false  }    return true;} function isChinese(s,thisInput) { //是中文  //去掉空格  try{    thisInput.value=thisInput.value.trim();  }catch(e){       }  s=s.trim();     if(s.length ==0){    return true;  }     var ret = ischinese(s);  if(!ret){    writeValidateInfo("請輸入中文", thisInput);    return ret;  }   return ret;} function notChinese(s,thisInput) { //不含中文  //去掉空格  try{    thisInput.value=thisInput.value.trim();  }catch(e){       }  s=s.trim();     if(s.length ==0){    return true;  }       var ret = ischinese(s);     if(ret){    writeValidateInfo("不能輸入中文",thisInput);    return false;  }   return true;} function isNum(s,thisInput) { //是數(shù)字   //去掉空格  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 ("請輸入數(shù)字!",thisInput);         return false;    }    i++;  }  return true;} function isNumBigtoZero(s,thisInput) { //是數(shù)字   //去掉空格  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 ("請輸入數(shù)字!",thisInput);         return false;    }    i++;  }  try{    if(thisInput.value<=0){      writeValidateInfo ("輸入數(shù)值必須大于零!",thisInput);      return false;    }  }catch(e){       }  return true;}function isEmail(s,thisInput) { //是電子郵件  //去掉空格  try{    thisInput.value=thisInput.value.trim();  }catch(e){       }  s=s.trim();     if(s.length ==0){    return true;  }   if (s.length > 100) {    writeValidateInfo("email地址長度不能超過100位!",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 ("請輸入有效合法的E-mail地址 !",thisInput);    return false;  }} function isIP() { //是IP       var patrn=/^[0-9.]{1,20}$/;   if (!patrn.exec(s)){    writeValidateInfo('請輸入IP值!',thisInput);    return false  }   return true;}  /***********************************************************************Venus Web JavaScript Code:HTC 校驗notNull***********************************************************************/function notNullWithoutTrim(s,thisInput) { //是""  //去掉空格  try{    thisInput.value=thisInput.value.trim();  }catch(e){       }  s=s.trim();     if ( s.length == 0){    writeValidateInfo('請輸入,該項不能為空!',thisInput);    return false;  }   return true;} function isInteger(str,thisInput) { //是整數(shù)  //去掉空格  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('請輸入整數(shù)!',thisInput);      return false;    }  }  return true;}function isNormalStrOnWeb(s,thisInput) { //是普通字符(非html標(biāo)記)  if (s.substring(0,1) == "<" || s.substring(0,1) == "/>" || s.substring(0,1) == " "){      writeValidateInfo("焦點處不能以<或/>或空格開頭",thisInput);      return false;  }   if (!HoldCode(s)){    writeValidateInfo("焦點處不能輸入全角/"?/"http://"―/"http://"――/"字符",thisInput);    return false;  }  if (s.trim().length > 0){    if (s.indexOf("/"") > -1){      writeValidateInfo("焦點處不能輸入雙引號!!",thisInput);      return false;    }    if (s.indexOf("/'") > -1){      writeValidateInfo("焦點處不能輸入單引號",thisInput);      return false;    }    if (s.indexOf("http://") > -1){      writeValidateInfo("焦點處不能輸入 '//' ",thisInput);      return false;    }  }  return true;}    //基本函數(shù)列表function Jtrim(str) { //去空隔函數(shù)  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) { //數(shù)字判斷函數(shù)  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) { //判斷是否中文函數(shù)  var ret=true;  for(var i=0;i<s.length;i++)    ret=ret && (s.charCodeAt(i)>=10000);  return ret;} /***********************************************************************Venus Web JavaScript Code:HTC 表單通用檢驗(完善中)***********************************************************************/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("焦點處不能以<或/>或空格開頭");          current_form[i].focus();          current_form[i].select();          return false;      }       if (getStrLength(current_form[i].value) > current_form[i].maxLength){          alert("焦點處輸入長度超長/n請確保輸入長度在" +current_form[i].maxLength+"以內(nèi)");          current_form[i].focus();          current_form[i].select();          return false;      }      if (!HoldCode(current_form[i].value)){        alert("焦點處不能輸入全角/"?/"http://"―/"http://"――/"字符");        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("焦點處不能輸入雙引號");          current_form[i].focus();          current_form[i].select();          return false;        }      }    }  }  return true;}    function checkNumber(s, inputName) {  try{    //去掉空格    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) { //校驗運(yùn)行里程,小數(shù),整數(shù)部分最多為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("整數(shù)部分最大為" + (maxLength - scale) + "位!");      return false;    }  } else {    if(s.length <= maxLength) {      return true;    } else {      alert("整數(shù)部分最大為" + maxLength + "位!!");      return false;    }  }} function isFloatNumber(s,inputName) { //判斷是否  //去掉空格  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("請輸入有效數(shù)字!", inputName);          return false;    }    i++;  }  if(s.indexOf(".") != s.lastIndexOf(".")) {    alert("小數(shù)點不對,請輸入有效數(shù)字!");    return false;  } else {    return true;  }} function isSearch(s,thisInput) { //不能輸入非法字符  if(s.length == 0 )     return true;  var patrn=/^[^`~!@#$%^&*()+=|///][/]/{/}:;'/,.<>/?]{1}[^`~!@$%^&()+=|///][/]/{/}:;'/,.<>?]{0,5000}$/;   var patrn2 = /[^/{/|/.//,<>"'_}/]/;  if (!patrn.exec(s) || !patrn2.exec(s)){    writeValidateInfo('輸入項中含非法字符,請重新輸入!',thisInput);    return false;    }  return true ;}  //===============================================================================================/** * 驗證數(shù)字(正整數(shù)或者包含小數(shù)的數(shù)字). */function isNumeric(value, thisInput) {  //去掉空格  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 ("請輸入正整數(shù)或者小數(shù)!", thisInput);    return false;  }   return true;}  /** * 驗證數(shù)字(正整數(shù)). */function checkInt(value, thisInput) {  //去掉空格  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 ("請輸入正整數(shù)!", thisInput);    return false;  }   return true;}/** * 驗證數(shù)字(整數(shù)位最大為10位,可以帶小數(shù)) */function validateNumericAndLength(value, thisInput) {  //去掉空格  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 ("請輸入正整數(shù)或者小數(shù)(整數(shù)位只能有10位)!", thisInput);        return false;  }   return true;} /** * 驗證數(shù)字(18,2) */function isNum18p2(value, thisInput) {  //去掉空格  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 ("請輸入數(shù)字(整數(shù)位最多16位,小數(shù)位最多2位)!", thisInput);       return false;  }  return true;} /** * 驗證數(shù)字(18,4) */function isNum18p4(value, thisInput) {  //去掉空格  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 ("請輸入數(shù)字(整數(shù)位最多14位,小數(shù)位最多4位)!", thisInput);       return false;  }  return true;}  /** * 驗證數(shù)字(5,2) */function isNum5p2(value, thisInput) {  //去掉空格  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 ("請輸入數(shù)字(整數(shù)位最多3位,小數(shù)位最多2位)!", thisInput);        return false;  }  return true;} /** * 驗證Email. */function checkEmail(value, thisInput) {  //去掉空格  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 ("請輸入正確的Email地址!", thisInput);    return false;  }   return true;} /** * 驗證身份證(15位或者18位身份證). */function checkIdCard(value, thisInput) {  //去掉空格  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 ("請輸入正確的身份證號碼!", thisInput);    return false;  }   return true;} /** * 驗證郵政編碼. */function checkPostCode(value, thisInput) {  //去掉空格  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 ("請輸入正確的郵政編碼!", thisInput);    return false;  }   return true;} /** * 驗證是否為中文字符. */function checkChinese(value, thisInput) {  //去掉空格  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 ("請輸入中文字符!", thisInput);    return false;  }   return true;} /** * 驗證是否為非法字符. */function checkInvalidString(value, thisInput) {  var reg = /^[^`~!@#$%^&*()+=|///][/]/{/}:;'/,.<>/?]*$/;   if (!reg.exec(value)) {    writeValidateInfo ("輸入的字符中包含特殊字符,請重新輸入!", thisInput);    return false;  }   return true;} function checkMoney(s, inputName) {  //去掉空格  try{    thisInput.value=thisInput.value.trim();  }catch(e){       }  s=s.trim();     if(s.length ==0){    return true;  }     if(s==""){    writeValidateInfo("金額不能為空!", inputName);    return false;  }  if(isFloatNumber(s,inputName)==false){    writeValidateInfo("非法金額值!", inputName);    return false;  }  var maxLength = 10;  var scale =2;  return checkNumberImpl(s, maxLength, scale,inputName);} /** * 校驗分?jǐn)?shù)是否在0-100 */function isAdultAge(str,thisInput) { //是整數(shù)   //去掉空格   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('請輸入合法分?jǐn)?shù)(0--100之間)!',thisInput);    return false;  }  return true;}   /** * 6 級強(qiáng)度設(shè)置(數(shù)字、大寫字母、小寫字母、特殊字符、長度>=6、長度>=10) * 如果密碼為空,返回 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) //數(shù)字      sum[0] = 1;    else if (c >=65 && c <=90) //大寫字母      sum[1] = 1;    else if (c >=97 && c <=122) //小寫字母      sum[1] = 1;    else //特殊字符      sum[2] = 1;   }  var level = sum[0] + sum[1] + sum[2] ;  if (pwd.length >= 8) level++;  return level;}function isBiggerZero(value, thisInput) { //已經(jīng)是數(shù)字,然后必須大于0  if(thisInput.value<=0){    writeValidateInfo('請輸入一個大于零的數(shù)字!',thisInput);    return false;  }  return true;} function isNonnegative(value, thisInput) {   if(thisInput.value<0){    writeValidateInfo('請輸入一個非負(fù)的數(shù)字!',thisInput);    return false;  }  return true;} /** * 驗證數(shù)字(20,6) */function isNum20p6(value, thisInput) {  //去掉空格  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 ("請輸入數(shù)字(整數(shù)位最多14位,小數(shù)位最多6位)!", thisInput);       return false;  }  return isBiggerZero(value, thisInput);} /** * 驗證數(shù)字(18,6) */function isNum18p6(value, thisInput) {  //去掉空格  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 ("請輸入數(shù)字(整數(shù)位最多12位,小數(shù)位最多6位)!", thisInput);       return false;  }  return isBiggerZero(value, thisInput);} function isNonnegative20p6(value, thisInput) {  //去掉空格  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 ("請輸入數(shù)字(整數(shù)位最多14位,小數(shù)位最多6位)!", thisInput);       return false;  }  return isNonnegative(value, thisInput);} /** * 驗證數(shù)字(20,4) */function isNum20p4(value, thisInput) {  //去掉空格  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 ("請輸入數(shù)字(整數(shù)位最多16位,小數(shù)位最多4位)!", thisInput);       return false;  }  return isBiggerZero(value, thisInput);} /** * 供應(yīng)商輸入的單批次保證金金額只能是正整數(shù)并且只能精確到百位 */function isDPCBZJ(value, thisInput) {  //去掉空格  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 ("請輸入正確的保證金金額!", thisInput);    return false;  }   return true;} //報表招標(biāo)年度起始年度不能大于終止年度的判斷function validateYear(startYear,endYear,flag) {  if(startYear > endYear){    if(flag==1){      alert("起始月份不能大于終止月份");       return false;     }else{      alert("招標(biāo)起始年度不能大于終止年度");      return false;     }  }  return true;}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 免费在线观看一级片 | 久久成人午夜视频 | 我爱我色成人网 | 玩偶姐姐在线观看免费 | 午夜视频啊啊啊 | 久久新地址 | 羞羞的网址 | 久久久久国产精品久久久久 | 鸳鸯谱在线观看高清 | 久久国产精品成人免费网站 | 日本羞羞的午夜电视剧 | 特级黄aaaaaaaaa毛片 | 久章草在线视频 | 日韩一级成人 | 欧美成年人视频 | 深夜福利久久久 | 日韩精品中文字幕一区二区 | 欧美 亚洲 激情 | 欧洲成人av | 黑人一区二区三区四区五区 | 欧美一级做a | 久久久噜噜噜久久熟有声小说 | 黄色免费小网站 | 国产精品午夜未成人免费观看 | 久久久久久久一区二区三区 | 少妇一级淫片高潮流水电影 | 日本a∨精品中文字幕在线 被啪羞羞视频在线观看 | 欧美精品a∨在线观看不卡 午夜精品影院 | 成人免费av在线播放 | 成人短视频在线观看免费 | 91,视频免费看 | 色播视频在线播放 | 成人午夜在线免费观看 | 久久国产精品久久久久久久久久 | 色999国产| 激情97| 性片免费看 | 美女久久 | 天天色综合2 | 嫩草91在线 | 韩国精品一区二区三区四区五区 |