文章详情

input 文本筐只能输入中文或数字及长度控制

2013/4/16 18:16:26    小编:胡金金个人网站

只能输入数字
<input onKeyUp="value=value.replace(/D+/g,\'\')">
只能输入中文
<input onKeyUp="value=value.replace(/[ -}]/g,\'\')">

字符长度

form onsubmit=check(this.test4,4)>
<input name=test4 onKeyUp="value=value.replace(/[ -}]/g,\'\')">><input type=submit>
</form>
<script>
function check(ob,num){
if(ob.value.length>=num)
    return;
alert("4 or more characters expected");
event.returnValue=false;
}
</script>

个人资讯推荐