JS中只能输入数字和“.”的正则表达式

^([0-9.]+)$

这个对不对??

第1个回答  2008-12-04
这是测试的代码,希望有用:

<script>
var x="345asdfwe23234.";
x=x.replace(/[0-9\.]+/g,"");
alert(x);
if(x.length>0)
alert("wrong");
</script>
第2个回答  推荐于2016-08-20

测试如下:
<html>
<head>
<script language = "javascript">
function test() {
var pattern = /^([0-9.]+)$/;
var str = prompt("Enter the test string","");
if (pattern.test(str)) {
alert(true);
} else {
alert(false);
}
}
</script>
</head>
<body>
<input type = "button" value = "test" onclick = "test()" />
</body>
</html>本回答被提问者采纳
第3个回答  2008-12-04
对的
相似回答