| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 820 人关注过本帖
标题:如何判断在文本框上输入的全是数字
只看楼主 加入收藏
风中的承诺
Rank: 1
等 级:新手上路
帖 子:331
专家分:0
注 册:2004-10-31
收藏
 问题点数:0 回复次数:7 
如何判断在文本框上输入的全是数字
如何判断在文本框上输入的全是数字

<input type=" text"


搜索更多相关主题的帖子: 文本框 数字 判断 输入 input 
2006-03-06 21:25
rainic
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:2367
专家分:0
注 册:2005-8-9
收藏
得分:0 
在服務器端可以用
isnumeric

在客戶端可以用js的isNan

2006-03-06 21:53
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
我习惯在服务器端验证。
方法
<script language=javascript>
<%
On Error Resume Next
IF VarType(CInt(Request.From("textfield1")))<>2 Then
Response.Write "alert('输入非数字');"
End IF
%>
</script>
2006-03-06 22:05
风中的承诺
Rank: 1
等 级:新手上路
帖 子:331
专家分:0
注 册:2004-10-31
收藏
得分:0 
以下是引用yms123在2006-3-6 22:05:00的发言:
我习惯在服务器端验证。
方法
<script language=javascript>
<%
On Error Resume Next
IF VarType(CInt(Request.From("textfield1")))<>2 Then
Response.Write "alert('输入非数字');"
End IF
%>
</script>

可以帮忙说明一下吗? <>2是什么意思?


I love you not because of who you are, but because of who I am when I am with you!
2006-03-08 16:30
anjincheng
Rank: 2
等 级:论坛游民
威 望:5
帖 子:728
专家分:31
注 册:2005-7-27
收藏
得分:0 

[CODE]<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!-- #include file="conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>:::判断输入框是否为数字:::</title>
</head>

<body bgcolor="#6699cc" onload="setup()" >

<form name="input_form" action="add_panduan.asp" method="post" onSubmit="return checkform();">

<input name="panduan" type="text" class="inputform1" id="panduan" onMouseOver="this.focus();" size="10">

<input type=submit value=完成录入 name=Submit>
<input type=reset value=清空重写 name=Submit_a>
</form>

<script language="JavaScript" >
function checkform()
{
var subst = document.input_form;
if (subst.panduan.value=="")
{
alert("对不起!判断内容不能为空哦!");
subst.panduan.focus();
return false;
}
if (subst.panduan.value!="")
{
if(onlyNum(subst.panduan.value)==0)
{
alert("对不起!判断内容只能输入数字!");
subst.panduan.focus();
return false;
}
}
return true;
}


function onlyNum(NUM)
{
var i,j,strTemp;
strTemp="0123456789";
if ( NUM.length== 0)
return 0
for (i=0;i<NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j==-1)
{
//说明有字符不是数字
return 0;
}
}
//说明是数字
return 1;
}
</script>
</html>[/CODE]


我是农家的孩子,我有农家孩子的本色!
2006-03-08 18:05
anjincheng
Rank: 2
等 级:论坛游民
威 望:5
帖 子:728
专家分:31
注 册:2005-7-27
收藏
得分:0 

[CODE]<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!-- #include file="conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>:::判断输入框是否为数字:::</title>
</head>

<body bgcolor="#6699cc" onload="setup()" >

<form name="input_form" action="add_panduan.asp" method="post" onSubmit="return checkform();">

<input name="panduan" type="text" class="inputform1" id="panduan" onMouseOver="this.focus();" size="10">

<input type=submit value=完成录入 name=Submit>
<input type=reset value=清空重写 name=Submit_a>
</form>

<script language="JavaScript" >
function checkform()
{
var subst = document.input_form;
if (subst.panduan.value=="")
{
alert("对不起!判断内容不能为空哦!");
subst.panduan.focus();
return false;
}
if (subst.panduan.value!="")
{
if(onlyNum(subst.panduan.value)==0)
{
alert("对不起!判断内容只能输入数字!");
subst.panduan.focus();
return false;
}
}
return true;
}


function onlyNum(NUM)
{
var i,j,strTemp;
strTemp="0123456789";
if ( NUM.length== 0)
return 0
for (i=0;i<NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j==-1)
{
//说明有字符不是数字
return 0;
}
}
//说明是数字
return 1;
}
</script>
</html>[/CODE]


我是农家的孩子,我有农家孩子的本色!
2006-03-08 18:07
风中的承诺
Rank: 1
等 级:新手上路
帖 子:331
专家分:0
注 册:2004-10-31
收藏
得分:0 
谢谢

I love you not because of who you are, but because of who I am when I am with you!
2006-03-09 12:39
anjincheng
Rank: 2
等 级:论坛游民
威 望:5
帖 子:728
专家分:31
注 册:2005-7-27
收藏
得分:0 
不晓得是不是您需要的。

我是农家的孩子,我有农家孩子的本色!
2006-03-09 12:49
快速回复:如何判断在文本框上输入的全是数字
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024702 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved