js 验证数字(验证字符串是否是数字)

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>js 验证数字(验证字符串是否是数字)</title>
<script language="网页特效">

function isnumericvalid(bwrnumber)
{

var validchars = "0123456789";
var isnumber=true;
var char;

for (i = 0; i < bwrnumber.length && (www.111cn.net)isnumber == true; i++)
{
char = bwrnumber.charat(i);
if (validchars.indexof(char) == -1)
{
isnumber = false;
}
}
return isnumber;
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<label for="textfield"></label>
<input type="text" name="a" id="a" />
<input type="button" name="button" id="button" value="按钮" onclick="isnumericvalid(form1.a.value);" />
</form>
</body>
</html>
from:http://www.111cn.net/wy/js-ajax/35320.htm

posted @ 2015-03-05 15:23  绫来  阅读(461)  评论(0编辑  收藏  举报