⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commoncheck.js

📁 梦界家园程序开发基底框架
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*-------------------------------------------------------------
 * 僼傽僀儖柤丂:丂common.js
 *
 * 嶌惉擔晅      嶌惉幰        僶乕僕儑儞    奣梫
 * 2004/04/15    Fcy            1.0        怴婯嶌惉
 * 
 * 仸拲堄彂偒
 * 丂丒submit偟偨嵺偼丄buttonHidden 傪幚峴偟儃僞儞椶傪disable壔偟偰壓偝偄
 *   丒報嶞張棟傪峴偆嵺偼丄openPrintWindow 傪幚峴偟僂傿儞僪僂傪棫偪忋偘偰壓偝偄
 *   
-------------------------------------------------------------*/
/**
 * 僄儔乕僠僃僢僋傪峴偆偐偳偆偐傪敾抐偡傞丅
 * change僀儀儞僩偲blur僀儀儞僩偺椉曽偱僠僃僢僋偡傞応崌偵巊梡偡傞丅
 * 
 */ 
function isCheck(){
  var blnResult = true;
  var blnChange = window.event.type == "change";
  var blnBlur = window.event.type == "blur";

  if(blnChange){
    blnResult = true;
    excErrCheck = false;
  }else if(blnBlur && excErrCheck){
    blnResult = true;
    excErrCheck = true;
  }else{
    blnResult = false;
    excErrCheck = true;
  }
  
  return blnResult;

}

/**
 * 暥帤楍偑悢抣偺傒偱峔惉偝傟偰偄傞偐傪僠僃僢僋偡傞
 * @param strInput 僠僃僢僋懳徾偺暥帤楍
 * @return boolean 悢抣偺傒側傜 true 偦偆偱側偗傟偽 false
 */
function checkNumber(num) {
  try{
    if(num*1>0){
      return true;
    }else{
      return false;
    }
  }catch(e){
    return false;
  }
}

/**
 * 暥帤楍拞偑慡偰敿妏暥帤偱偁傞偐僠僃僢僋偡傞
 * @param strInput 僠僃僢僋懳徾偺暥帤楍
 * @return boolean 敿妏暥帤偺傒側傜 true 偦偆偱側偗傟偽 false
 */
function checkStringSingle(strInput) {
  /* 敿妏僇僞僇僫 */
  //僺儕僆僪(MIDDEL DOT)傪桳岠偵偡傞
  //var hanKanaStart = "0xFF66"
  var hanKanaStart = "0xFF61"
  var hanKanaEnd = "0xFF9F"
  var charCd;
  if ( strInput.length <= 0 ) {
    return true;
  }
  for (var i = 0; i < strInput.length; i++) {
    if ( escape( strInput.charAt(i) ).length >= 4 ) {
      charCd = "0x" + escape( strInput.charAt(i) ).substring(2);
      if ( eval(charCd) < eval(hanKanaStart) || eval(hanKanaEnd) < eval(charCd) ) {
        return false;
      }
    }
  }
  return true;
}

/**
 * 暥帤楍偑敿妏塸悢偺傒偱峔惉偝傟偰偄傞偐傪僠僃僢僋偡傞
 * @param strInput 僠僃僢僋懳徾偺暥帤楍
 * @return boolean 敿妏塸悢偺傒側傜 true 偦偆偱側偗傟偽 false
 */
function checkAlphabet(strInput) {
    for (i=0;i<strInput.length;i++){
      code = strInput.charCodeAt(i);
      if ((48 > code || code > 57) && (65 >  code || code > 90) && (97 > code || code > 122)){
        return false;
      }
    }
  return true;
}

/**
 * 暥帤楍拞偑慡偰慡妏暥帤偱偁傞偐僠僃僢僋偡傞
 * @param strInput 僠僃僢僋懳徾偺暥帤楍
 * @return boolean 慡妏暥帤乮2僶僀僩暥帤乯偺傒側傜 true 偦偆偱側偗傟偽 false
 */
function checkString2byte(strInput) {
  /* 敿妏僇僞僇僫 */
  //僺儕僆僪(MIDDEL DOT)傪桳岠偵偡傞
  //var hanKanaStart = "0xFF66"
  var hanKanaStart = "0xFF65"
  var hanKanaEnd = "0xFF9F"
  var charCd;
  if ( strInput.length <= 0 ) {
    return true;
  }
  for (var i = 0; i < strInput.length; i++) {
    if ( escape( strInput.charAt(i) ).length < 4 ) {
      return false;
    }
    charCd = "0x" + escape( strInput.charAt(i) ).substring(2);
    if ( eval(hanKanaStart) <= eval(charCd) && eval(charCd) <= eval(hanKanaEnd) ) {
      return false;
    }
  }
  return true;

}

/**
 * 枹擖椡僠僃僢僋(奺僼傿乕儖僪僞僀僾偛偲)
 * <br>
 * @param  field   懳徾僼傿乕儖僪
 * @return true - 擖椡偁傝丂false - 擖椡柍偟
 */
function checkRequired(strInput) {
  if ( typeof(strInput) == "undefined" ) {
    return true;
  }
  if ( strInput.type == 'text' ||
      strInput.type == 'textarea' ||
      strInput.type == 'password' || strInput.type == 'hidden' ) {
    if ( trim( strInput.value ).length == 0 ) {
      return false;
    }
  } else if ( strInput.type == 'select-one' ) {
    var si = strInput.selectedIndex;
    if ( (si < 0) || trim( strInput.options[si].value ) == "" ) {
      return false;
    }
  } else if ( strInput.type == 'checkbox' ) {
    return strInput.checked;
  } else if ( strInput.type == 'radio' ) {
    if ( getRadioValue( strInput ) == null ) {
      return false;
    }
  } else if ( typeof(strInput.type) == "undefined" ) {
    if ( strInput.length != null ) {
      if ( strInput[0].type == 'radio' ) {
        if ( getRadioValue( strInput ) == null ) {
          return false;
        }
      } else {
        // 攝楍崁栚偺応崌偼偄偢傟偐堦偮偵擖椡偑偁傟偽OK
        for (var i = 0; i < strInput.length; i++) {
          if ( checkRequired( strInput[i] ) ) {
            return true;
          }
        }
        return false;
      }
    }
  }
  return true;
}

/**
 * 暥帤楍偺僶僀僩悢傪僠僃僢僋偡傞丅
 * 
 * @param strInput 僠僃僢僋懳徾偺暥帤楍
 * @param intMaxLength 嵟戝僶僀僩悢
 * @return boolean 惓偟偗傟偽 true 偦偆偱側偗傟偽 false
 */
function checkLength(strInput,intMaxLength) {
  /* 敿妏僇僞僇僫 */
  //僺儕僆僪(MIDDEL DOT)傪桳岠偵偡傞
  //var hanKanaStart = "0xFF66"
  var hanKanaStart = "0xFF65"
  var hanKanaEnd = "0xFF9F"
  var charCd;
  count = 0;
  for (i=0; i<strInput.length; i++){
    n = escape(strInput.charAt(i));
    if (n.length < 4) {
      count++;
    }else{
      charCd = "0x" + escape( strInput.charAt(i) ).substring(2);
      if ( eval(hanKanaStart) <= eval(charCd) && eval(charCd) <= eval(hanKanaEnd) ) {
        count++;
      }else{
        count+=2;
      }
    }
  }

  if(count>intMaxLength){
    return false;
  }else{
    return true;
  }
}

/**
 * 暥帤楍偺僶僀僩悢傪僠僃僢僋偡傞丅
 * 
 * @param strInput 僠僃僢僋懳徾偺暥帤楍
 * @param intMaxLength 嵟彫僶僀僩悢
 * @return boolean 惓偟偗傟偽 true 偦偆偱側偗傟偽 false
 */
function checkLengthMin(strInput,intMinLength) {
  /* 敿妏僇僞僇僫 */
  //僺儕僆僪(MIDDEL DOT)傪桳岠偵偡傞
  //var hanKanaStart = "0xFF66"
  var hanKanaStart = "0xFF65"
  var hanKanaEnd = "0xFF9F"
  var charCd;
  count = 0;
  for (i=0; i<strInput.length; i++){
    n = escape(strInput.charAt(i));
    if (n.length < 4) {
      count++;
    }else{
      charCd = "0x" + escape( strInput.charAt(i) ).substring(2);
      if ( eval(hanKanaStart) <= eval(charCd) && eval(charCd) <= eval(hanKanaEnd) ) {
        count++;
      }else{
        count+=2;
      }
    }
  }

  if(count<intMinLength){
    return false;
  }else{
    return true;
  }
}

/**
 * 彫悢偺惍悢晹暘寘悢偲彫悢晹暘寘悢偺僠僃僢僋
 *
 * @param strInput 僠僃僢僋懳徾偺暥帤楍
 * @param intNum1 惍悢晹暘偺寘悢
 * @param intNum2 彫悢晹暘偺寘悢
 * @return 僠僃僢僋寢壥丅宍幃偑惓偟偗傟偽true丄巜掕偟偨宍幃偱側偗傟偽false
 */
function checkDecimal(strInput,intNum1,intNum2) {
  if(strInput.indexOf(".",0) <= 0){
    if(strInput.length > intNum1){
      return false;
    }else{
      return true;
    }
  }else{
    if((strInput.split(".")[0]).length > intNum1){
      return false;
    }else if((strInput.split(".")[1]).length > intNum2){
      return false;
    }else{
      return true;
    }
  }
}


/**
 * 暥帤楍偑悢抣偺傒偱峔惉偝傟偰偄偰巜掕僶僀僩悢偄側偄偐僠僃僢僋偡傞
 * @param strInput 僠僃僢僋懳徾偺暥帤楍
 * @param intMax 巜掕僶僀僩悢
 * @return boolean 悢抣偺傒偱峔惉偝傟偰偄偰巜掕僶僀僩悢埲撪側傜 true 偦偆偱側偗傟偽 false
 */
function checkNumberSize(strInput,intMax) {
    if (checkNumber(strInput) && checkLength(strInput,intMax) ) {
        return true;
    }else{
        return false;
    }
}

/**
 * 暥帤楍拞偑慡偰敿妏暥帤偱偁傝丄巜掕僶僀僩悢埲撪偐僠僃僢僋偡傞
 * @param strInput 僠僃僢僋懳徾偺暥帤楍
 * @param intMax 巜掕僶僀僩悢
 * @return boolean 敿妏暥帤偺傒偱峔惉偝傟偰偄偰巜掕僶僀僩悢埲撪側傜 true 偦偆偱側偗傟偽 false
 */
function checkStringSingleSize(strInput,intMax) {
    if (checkStringSingle(strInput) && checkLength(strInput,intMax) ) {
        return true;
    }else{
        return false;
    }
}

/**
 * 暥帤楍偑敿妏塸悢偺傒偱峔惉偝傟偰偍傝丄巜掕僶僀僩悢埲撪偐傪僠僃僢僋偡傞
 * @param strInput 僠僃僢僋懳徾偺暥帤楍
 * @param intMax 巜掕僶僀僩悢
 * @return boolean 敿妏塸悢偺傒偱峔惉偝傟偰偄偰巜掕僶僀僩悢埲撪側傜 true 偦偆偱側偗傟偽 false
 */
function checkAlphabetSize(strInput,intMax) {
    if (checkAlphabet(strInput) && checkLength(strInput,intMax) ) {
        return true;
    }else{
        return false;
    }
}

/**
 * 暥帤楍拞偑慡偰慡妏暥帤偱偁傝巜掕僶僀僩悢埲撪偱偁傞偐僠僃僢僋偡傞
 * @param strInput 僠僃僢僋懳徾偺暥帤楍
 * @param intMax 巜掕僶僀僩悢
 * @return boolean 慡妏暥帤偺傒偱峔惉偝傟偰偄偰巜掕僶僀僩悢埲撪側傜 true 偦偆偱側偗傟偽 false
 */
function checkString2byteSize(strInput,intMax) {
    if (checkString2byte(strInput) && checkLength(strInput,intMax) ) {
        return true;
    }else{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -