<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>js限制只能输入数字</title>
<script language="网页特效">
function ispositive(strnumber)
{
re=/^[0-9]+.{0,1}[0-9]{0,2}$/;
var str = strnumber.replace(/(^s*)|(s*$)/g, "");
if(str == "")
return true;
else
return (re.test(str))?true:false;
}
function ck()
{
var value = document.getelementbyid('numeric').value;
if( ispositive( value ) && value !="" )
{
alert('全部是数字');
}
else
{
alert('必须全是数字');
form1.numeric.select();
}
}
</script>
</head><body>
<form id="form1" name="form1" method="post" action="">
<label for="textfield"></label>
<input type="text" name="numeric" id="numeric" />
<input type="button" name="button" id="button" value="按钮" onclick="ck();"/>
</form>
</body>
</html>