求一个只能输入大写字母和数字的正则表达式! 需求B/S ,input中输入只能是数字和字母,个数为5,小写自动转大写,不是退出的时候转大写,而是输入小写,显示为大写。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var re = /[A-Z0-9]{5}/;匹配大写和数字 有个样式可以自动转换大小写text-transform: uppercase值只能输入的话可以判断onkeydown或onkeypress事件的ASCII不在范围内return false 在js里用1楼的验证啊,验证完了用str.toUpperCase(); 将字符串里的小写转成大写,再返回 <input type="text" name="username" onkeypress='return /^[0-9a-zA-Z]{0,4}$/.test(this.value)' style="text-transform: uppercase"> <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> var re = /[A-Z|a-z|0-9]{5}/; 验证完了用str.toUpperCase(); 用以下可阻止输入非数字,字母数据,并控制字数不超过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()"> 参考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>这个应该是比较好的解决方法. 在GB2312的字符集下 关于用JS实现三联动,高手快进来啊 ,急! 判断用户名是否合法 javascript嵌入服务脚本的问题!100分!近来就有! 打印预览:没有权限!!! “与”关系统的值如何取得? 用javaScript打开窗口后,原窗口的gif动画不动了 document.getElementById("cssname").value= "大版.css"; 传值无效 javascript中双引号与单引号的区别? js求表单指定一列数据相加的函数,增加一行数据,结果自动累加并展示在调用窗口 求教下拉菜单显示的问题 javascript 如何判断capslock键是否开启?
text-transform: uppercase值只能输入的话可以判断onkeydown或onkeypress事件的ASCII不在范围内return false
name="username"
onkeypress='return /^[0-9a-zA-Z]{0,4}$/.test(this.value)'
style="text-transform: uppercase">
<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>
<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()">
<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>
这个应该是比较好的解决方法.