前几天刚写了一个check函数,给你代码自己看看吧true : 检验代码正确
false: 检验代码错误   function num_chk(chk_str) {
   var wk_c_len;
    if (chk_str == "") return true;
    wk_c_len = chk_str.length;
    for (wk_i = 0;wk_i < wk_c_len;wk_i++) {
      if (chk_str.charAt(wk_i) > '9'  || chk_str.charAt(wk_i) < '0') {
       if (chk_str.charAt(wk_i) != '.' && chk_str.charAt(0) != '-') {
          return false;
        }
      }
    }
    return true;
}   function num_chk(chk_str) {
   var wk_c_len;
    if (chk_str == "") return true;
    wk_c_len = chk_str.length;
    for (wk_i = 0;wk_i < wk_c_len;wk_i++) {
      if (chk_str.charAt(wk_i) < 'a'  && chk_str.charAt(wk_i) > 'z') {
                     return false;
        }
      }
    }
    return true;
}

解决方案 »

  1.   

    function isDouble(str)
      {
      var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
      var checkStr = str;
      var ifValid = true;
          for (i = 0;  i < checkStr.length;  i++)
          {
          ch = checkStr.charAt(i);
           for (j = 0;  j < checkOK.length;  j++)
            if (ch == checkOK.charAt(j))
                  break;
            if (j == checkOK.length)
            {
              ifValid = false;
              break;
            }
          }
      return ifValid;
      }
      

  2.   

    function check(strA)
    {
    var re = /[^A-Za-z0-9]/gi;
    a = strA.search(re)
    return(a==-1);
    }alert(check("sdfjkdfjg4ldfkjg"));