怎样限制用户输入的都是数字???

怎样限制用户输入的数啊?包括小数点
---------------------------------------------------------------

 1<script language="JavaScript">   
 2  
 3function IsDigit(cCheck)   
 4{   
 5return (('0'<=cCheck) && (cCheck<='9') ¦ ¦(cCheck=='.') );   
 6}   
 7  
 8price = document.form1.price.value;   
 9if(price.length!=0)   
10for (nIndex=0; nIndex<price.length; nIndex++)   
11{   
12cCheck = price.charAt(nIndex);   
13if (!IsDigit(cCheck))   
14{   
15alert("单价只能使用数字和'.'。");   
16document.form1.price.focus();   
17return false;   
18}   
19}   
20</script>

---------------------------------------------------------------

set objregexp=new regexp
objregexp.Pattern ="[^0-9' \.]"
objregexp.IgnoreCase =true
dim strname
strname="123 "
if objregexp.Test (strname) then
Response.Write strname & "is not a valid name!

1<br/>

"
else
Response.Write strname & "is a valid name!

1<br/>

"
end if

补充刚才写的 ,我觉得这段代码最容易了
---------------------------------------------------------------

var str=form1.score.value;
mm=str.length;
for(i=0;i

 1<mm;i++){ if(str.charcodeat(i)="">'9' ¦ &amp;brvbarstr.charCodeAt(i)&lt;'0' ¦ &amp;brvbarstr.charCodeAt(i)&lt;&gt;'.')   
 2{   
 3alert("输入的不是数字");   
 4return false   
 5break;   
 6}   
 7}   
 8\---------------------------------------------------------------   
 9  
101、在<head></head>之间加入如下代码:   
11<script>   
12function checkNum(theForm){   
13var validmima   
14validmima="0123456789";   
15var strvaluemima=theForm.text1.value;   
16var allvalidstrmima=true;   
17for (var i=0;i < strvaluemima.length;i++)   
18{   
19ch=strvaluemima.charAt(i);   
20for (var j=0;j < validmima.length;j++)   
21if(ch == validmima.charAt(j))   
22break;   
23if(j == validmima.length){   
24allvalidstrmima=false;   
25break;   
26}   
27}   
28if (!allvalidstrmima){   
29alert("您输入的\"字符\"不是数字,请重新输入!");   
30theForm.text1.focus();   
31theForm.text1.value="";   
32return (false);   
33}   
34}   
35</script>   
362、在<body></body>之间加入如下代码:   
37<form action="" method="post" onsubmit="return checkNum(this)">
38<input name="text1" size="18" type="text"/>
39<input name="s1" type="submit" value="ok"/>
40</form></mm;i++){>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus