if((theForm.id.value.length == 15)||(theForm.id.value.length == 18))

解决方案 »

  1.   

    if((theForm.id.length == 15)||(theForm.id.length == 18))//id是什么对象///////
    <script>
    function check_input()
    {
    var flag=false;
    var val=document.all.Txt1.value;
    if((val.length == 15)||(val.length == 18))
    {
        flag=true;
    }
    if (!flag)
    {
    alert("身份证号的长度为15位或18位,您输入的长度不对!");
    document.all.Txt1.focus();
    return (false);
    }
    return (true);
    }
    </script>
    <input type=text id="Txt1" >
    <input type=button onclick=check_input() value=ooo>
      

  2.   

    function Len(str)
    {
        var i,sum;
        sum=0;
        for(i=0;i<str.length;i++)
        {
            if ((str.charCodeAt(i)>=0) && (str.charCodeAt(i)<=255))
                sum=sum+1;
            else
                sum=sum+2;
        }
        return sum;
    }
    --
    这个是检测长度
      

  3.   

    if((theForm.id.value.length == 15)||(theForm.id.value.length == 18))
    这个可以解决问题,但前后的多余的空格的话就不行,但前后的多余的空格如何去掉?
    id是一个表单中的textfiled
      

  4.   

    // Function Name: trim
    // Function Description: 去除字符串的首尾的空格
    // Creation Date: 2004-7-13 15:30
    // Last Modify By: N/A
    // Last Modify Date: N/A
    String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
    }
      

  5.   

    或许我的javascript太差了,我看不懂这个:
    String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
    }
    到底怎么引用这个函数呢?
      

  6.   

    <script>
    String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
    }
    var str="    12345678  ";
    str=str.trim();
    alert(str.length);
    </script>
      

  7.   

    在input输入控件中增加属性maxlength = 15