需求B/S ,input中输入只能是数字和字母,个数为5,小写自动转大写,不是退出的时候转大写,而是输入小写,显示为大写。

解决方案 »

  1.   

    var re = /[A-Z0-9]{5}/;匹配大写和数字
      

  2.   

    有个样式可以自动转换大小写
    text-transform: uppercase值只能输入的话可以判断onkeydown或onkeypress事件的ASCII不在范围内return false
      

  3.   

    在js里用1楼的验证啊,验证完了用str.toUpperCase(); 将字符串里的小写转成大写,再返回
      

  4.   

    <input type="text" 
      name="username" 
      onkeypress='return /^[0-9a-zA-Z]{0,4}$/.test(this.value)'  
      style="text-transform: uppercase">
      

  5.   

    <html>
    <head><title>this is excise</title>
    <script language='javascript'>
    function f1()
    {
      var re = /[A-Z0-9]{5}/;
    alert('here11');  
    //if()
    alert(document.getElementById("in1").value);
    if(document.getElementById("in1").value.length > 3)
    {  
    alert('yes');      
    value1 = document.getElementById("in1").value 
                 document.getElementById("in1").value = value1.toUpperCase(); ;
                 
    }

    else
    alert('no');
    }
    </script>
    </head>
    <body>
    <form action='1.html' method="get" >
    <tr>
    <td>
    <input type="text" id="in1" maxlength="5" >
    </td>
    </tr>
    <br>
    <tr>
    <td>
    <input type="text" id="in2" maxlength="5" >
    </td>
    </tr>
    <br>
    <tr>
    <td>
    <input type='button' name="submit" onclick="f1()">
    </td>
    </tr>
    </form>
    </body>
    </html>
      

  6.   

    var re = /[A-Z|a-z|0-9]{5}/; 验证完了用str.toUpperCase(); 
      

  7.   

    用以下可阻止输入非数字,字母数据,并控制字数不超过5个.
    <input type="text" name="username" 
    onkeypress='return /^[0-9a-zA-Z]{0,4}$/.test(this.value)'  
    style="text-transform: uppercase" 
    onchange="this.value=this.value.toUpperCase()">
      

  8.   

    参考xingqiliudehuanghun在别的地方写的.进行下修改
    <input type="text"  style="text-transform:uppercase"
           onInput="filtInput(this)" onkeyup="filtInput(this)" maxlength="6"/>
    JScript code<script>
    function filtInput(e){
            e.value=e.value.replace(/[^\d\w]/gi,""); 
    }
    </script>
    这个应该是比较好的解决方法.