茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    js驗(yàn)證框架實(shí)現(xiàn)代碼分享
    來源:易賢網(wǎng) 閱讀:1120 次 日期:2016-06-27 13:55:33
    溫馨提示:易賢網(wǎng)小編為您整理了“js驗(yàn)證框架實(shí)現(xiàn)代碼分享”,方便廣大網(wǎng)友查閱!

    這篇文章主要為大家分享了一個(gè)非常實(shí)用的js驗(yàn)證框架實(shí)現(xiàn)源碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

    本文實(shí)例為大家分享了js驗(yàn)證框架,很實(shí)用,供大家參考,具體內(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、驗(yàn)證時(shí)會(huì)自動(dòng)調(diào)用:isNumeric 方法 和 notNull方法并返回驗(yàn)證的結(jié)果信息。

    4、驗(yàn)證框架源碼如下

    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, "焦點(diǎn)處輸入長度超長\n請(qǐng)確保輸入長度在" +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("校驗(yàn)函數(shù)"+validateTemp[i]+"有異常,請(qǐng)檢查!" + "\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會(huì)導(dǎo)致文件上傳錯(cuò)誤

        _frm.focus();

        //由于SELCET不支持內(nèi)容選擇,且不用內(nèi)容選擇,所以特殊處理,防止報(bào)錯(cuò)

        //修改:李岳 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) { //寫校驗(yàn)信息

      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ù)點(diǎn)位數(shù)超過兩位", thisInput);

         return false;

      }else{

         return true;

       }

    }

    function isMobile(s, thisInput) { //是手機(jī)號(hào)碼:必須以數(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('請(qǐng)輸入合法的手機(jī)號(hào)碼!', 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('請(qǐng)輸入合法的手機(jī)號(hào)碼!', thisInput);

          return false;

        }

      }

      var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/; 

      if (!patrn.exec(s)) {

        writeValidateInfo('請(qǐng)輸入合法的手機(jī)號(hào)碼!', 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('請(qǐng)輸入合法的郵政編碼!', thisInput);

        return false;

      }

      return true;

    function isTel(s,thisInput) { //是電話普通電話、傳真號(hào)碼:可以“+”開頭,除數(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('請(qǐng)輸入合法的電話號(hào)碼!',thisInput);

        return false

      } 

      return true;

    }

    function isTelForFax(s,thisInput) { //是電話普通電話、傳真號(hào)碼:可以“+”開頭,除數(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('請(qǐng)輸入合法的座機(jī)號(hào)碼,例如:010-88888888!',thisInput);

        return false

      } 

      return true;

    }

    function isFax(s,thisInput) { //是電話普通電話、傳真號(hào)碼:可以“+”開頭,除數(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('請(qǐng)輸入合法的傳真號(hào)碼,例如: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("請(qǐng)輸入中文", 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 ("請(qǐng)輸入數(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 ("請(qǐng)輸入數(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 ("請(qǐng)輸入有效合法的E-mail地址 !",thisInput);

        return false;

      }

    }

    function isIP() { //是IP

      var patrn=/^[0-9.]{1,20}$/; 

      if (!patrn.exec(s)){

        writeValidateInfo('請(qǐng)輸入IP值!',thisInput);

        return false

      } 

      return true;

    }

    /**********************************************************************

    *Venus Web JavaScript Code:HTC 校驗(yàn)notNull

    ***********************************************************************/

    function notNullWithoutTrim(s,thisInput) { //是""

      //去掉空格

      try{

        thisInput.value=thisInput.value.trim();

      }catch(e){

      }

      s=s.trim();

      if ( s.length == 0){

        writeValidateInfo('請(qǐng)輸入,該項(xiàng)不能為空!',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('請(qǐng)輸入整數(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("焦點(diǎn)處不能以<或\>或空格開頭",thisInput);

          return false;

      }

      if (!HoldCode(s)){

        writeValidateInfo("焦點(diǎn)處不能輸入全角\"·\"/\"—\"/\"——\"字符",thisInput);

        return false;

      }

      if (s.trim().length > 0){

        if (s.indexOf("\"") > -1){

          writeValidateInfo("焦點(diǎn)處不能輸入雙引號(hào)!!",thisInput);

          return false;

        }

        if (s.indexOf("\'") > -1){

          writeValidateInfo("焦點(diǎn)處不能輸入單引號(hào)",thisInput);

          return false;

        }

        if (s.indexOf("\\") > -1){

          writeValidateInfo("焦點(diǎn)處不能輸入 '\\' ",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 表單通用檢驗(yàn)(完善中)

    ***********************************************************************/

    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("焦點(diǎn)處不能以<或\>或空格開頭");

              current_form[i].focus();

              current_form[i].select();

              return false;

          }

          if (getStrLength(current_form[i].value) > current_form[i].maxLength){

              alert("焦點(diǎn)處輸入長度超長\n請(qǐng)確保輸入長度在" +current_form[i].maxLength+"以內(nèi)");

              current_form[i].focus();

              current_form[i].select();

              return false;

          }

          if (!HoldCode(current_form[i].value)){

            alert("焦點(diǎn)處不能輸入全角\"·\"/\"—\"/\"——\"字符");

            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("焦點(diǎn)處不能輸入雙引號(hào)");

              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)運(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("請(qǐng)輸入有效數(shù)字!", inputName);    

          return false;

        }

        i++;

      }

      if(s.indexOf(".") != s.lastIndexOf(".")) {

        alert("小數(shù)點(diǎn)不對(duì),請(qǐng)輸入有效數(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('輸入項(xiàng)中含非法字符,請(qǐng)重新輸入!',thisInput);

        return false;  

      }

      return true ;

    }

    //===============================================================================================

    /**

     * 驗(yàn)證數(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 ("請(qǐng)輸入正整數(shù)或者小數(shù)!", thisInput);

        return false;

      }

      return true;

    }

    /**

     * 驗(yàn)證數(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 ("請(qǐng)輸入正整數(shù)!", thisInput);

        return false;

      }

      return true;

    }

    /**

     * 驗(yàn)證數(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 ("請(qǐng)輸入正整數(shù)或者小數(shù)(整數(shù)位只能有10位)!", thisInput);    

        return false;

      }

      return true;

    }

    /**

     * 驗(yàn)證數(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 ("請(qǐng)輸入數(shù)字(整數(shù)位最多16位,小數(shù)位最多2位)!", thisInput);   

        return false;

      }

      return true;

    }

    /**

     * 驗(yàn)證數(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 ("請(qǐng)輸入數(shù)字(整數(shù)位最多14位,小數(shù)位最多4位)!", thisInput);   

        return false;

      }

      return true;

    }

    /**

     * 驗(yàn)證數(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 ("請(qǐng)輸入數(shù)字(整數(shù)位最多3位,小數(shù)位最多2位)!", thisInput);    

        return false;

      }

      return true;

    }

    /**

     * 驗(yàn)證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 ("請(qǐng)輸入正確的Email地址!", thisInput);

        return false;

      }

      return true;

    }

    /**

     * 驗(yàn)證身份證(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 ("請(qǐng)輸入正確的身份證號(hào)碼!", thisInput);

        return false;

      }

      return true;

    }

    /**

     * 驗(yàn)證郵政編碼.

     */

    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 ("請(qǐng)輸入正確的郵政編碼!", thisInput);

        return false;

      }

      return true;

    }

    /**

     * 驗(yàn)證是否為中文字符.

     */

    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 ("請(qǐng)輸入中文字符!", thisInput);

        return false;

      }

      return true;

    }

    /**

     * 驗(yàn)證是否為非法字符.

     */

    function checkInvalidString(value, thisInput) {

      var reg = /^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]*$/;

      if (!reg.exec(value)) {

        writeValidateInfo ("輸入的字符中包含特殊字符,請(qǐng)重新輸入!", 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);

    }

    /**

     * 校驗(yàn)分?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('請(qǐng)輸入合法分?jǐn)?shù)(0--100之間)!',thisInput);

        return false;

      }

      return true;

    }

      /**

     * 6 級(jí)強(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('請(qǐng)輸入一個(gè)大于零的數(shù)字!',thisInput);

        return false;

      }

      return true;

    }

    function isNonnegative(value, thisInput) { 

      if(thisInput.value<0){

        writeValidateInfo('請(qǐng)輸入一個(gè)非負(fù)的數(shù)字!',thisInput);

        return false;

      }

      return true;

    }

    /**

     * 驗(yàn)證數(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 ("請(qǐng)輸入數(shù)字(整數(shù)位最多14位,小數(shù)位最多6位)!", thisInput);   

        return false;

      }

      return isBiggerZero(value, thisInput);

    }

    /**

     * 驗(yàn)證數(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 ("請(qǐng)輸入數(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 ("請(qǐng)輸入數(shù)字(整數(shù)位最多14位,小數(shù)位最多6位)!", thisInput);   

        return false;

      }

      return isNonnegative(value, thisInput);

    }

    /**

     * 驗(yàn)證數(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 ("請(qǐng)輸入數(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 ("請(qǐng)輸入正確的保證金金額!", thisInput);

        return false;

      }

      return true;

    }

    //報(bào)表招標(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)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:js驗(yàn)證框架實(shí)現(xiàn)代碼分享
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報(bào)班

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)