想要求从文本框输入的内容必须是10个数子
这个脚本语言怎么写啊

解决方案 »

  1.   

    function ck(){
      var re = /^\d{10}$/;
      var v = document.forms[0].xxx.value;
      if(!re.test(v)){
         alert('必须是10个数');
         return false
      }
      return true
    }
      

  2.   

    如果没有用过正则表达式,那么你可以用JavaScript中自己的方法,首先你判断必须为数字用NAN(),然后判断你输入的长度是否为10
      

  3.   

    function ck(){
      var re = /^\d{10}$/;
      var v = document.forms[0].xxx.value;
      if(!re.test(v)){
         alert('必须是10个数');
         return false
      }
      return true
    }
    建议学习下正则。
      

  4.   

    document.getElementById("id").value.length()