日期:2014-05-17  浏览次数:20726 次

js必须输入身份证的
输入身份证的输入框必须输入数字怎么写?
  
<html>  
<head>  
<meta http-equiv="content-Type" content="text/html;charset=gb2312">  
<title>js 只能输入数字和小数点</title>  
<script language="JavaScript" type="text/javascript">  
function clearNoNum(obj)  
{  
//先把非数字的都替换掉,除了数字和.  
obj.value = obj.value.replace(/[^\d.]/g,"");  
//必须保证第一个为数字而不是.  
obj.value = obj.value.replace(/^\./g,"");  
//保证只有出现一个.而没有多个.  
obj.value = obj.value.replace(/\.{2,}/g,".");  
//保证.只出现一次,而不能出现两次以上  
obj.value = obj.value.replace(".","$#{1}quot;).replace(/\./g,"").replace("$#{1}quot;,".");  
}  
</script>  
</head>  
<body>  
<!--把下面代码加到<body>与</body>之间-->  
只能输入数字和小数点的文本框:<input id="input1" onkeyup="clearNoNum(this)">  
</body>  
</html>  
报js错误,求个正确的能运行的。谢谢。最后93分了,群给你了

------解决方案--------------------
引用:
Quote: 引用:

就限制数字吗?


<html>
<head>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
</head>
<body>
只能输入数字和小数点的文本框:<input onkeyup="value=value.replace(/[^\d\.]/g,'')">
</body>
</html>

不要小数点啊。。小数点不行的


把\.去了

<html>
<head>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
</head>
<body>
只能输入数字和小数点的文本框:<input onkeyup="value=value.replace(/[^\d]/g,'')">
</body>
</html>