只允许输入字母或数字的文本框

来源:互联网 发布:淘宝起名符号 编辑:程序博客网 时间:2024/05/28 15:36

<html>

<head>
</head>

<body>
<input tpye="text" value="只允许输入字母" style="color:gray" onfocus="this.value='';this.style.color='black'"
onkeyup="this.value=this.value.replace(/[^a-z]/gi,'')">
<br>
<input tpye="text" value="只允许输入数字" style="color:gray" onfocus="this.value='';this.style.color='black'"
onKeyUp="this.value=this.value.replace(//D/gi,'');">
<br>
</body>
</html>

原创粉丝点击