怎样验证提交出来的数据不是数字类型?

xiaxin 2003-06-18 01:59:50
if (document.form1.gb_name.value=="")
{
alert("请填写姓名!");
document.form1.gb_name.focus();
return;
}
if (document.form1.gb_name.value.length>4)
{
alert("姓名不能超过4个汉字或字母!");
document.form1.gb_name.focus();
return;
}

我在书上翻了好久的函数,可惜书本太简单。没有验证是否是数字这个函数。。。请大侠指明。
...全文
91 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kinzey 2003-06-18
  • 打赏
  • 举报
回复
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<form name=myform>

<input type=text name=text>
<input value=check type=button onclick=chk()>

</form>
<script language=javascript>
function chk()
{
if (isNaN(document.myform.text.value)==false) alert("数字")
else alert("非数字")
}
</script>
</BODY>
</HTML>
summercat 2003-06-18
  • 打赏
  • 举报
回复
书上的例子.vbscript
r = 53
k = IsNumeric(r) ' 返回 True。

ar = "459.95"
ck = IsNumeric(ar) ' 返回True。
zhaoweiwei 2003-06-18
  • 打赏
  • 举报
回复
if(isNaN(yourstring))
MAGICSLIAO 2003-06-18
  • 打赏
  • 举报
回复
<Script Language="JavaScript">
<!--
var strValue="1";
iTest=strValue*0;
if(iTest!=0)
alert("字符型");
else
alert("数值型");
-->
</Script>
kingdomzhf 2003-06-18
  • 打赏
  • 举报
回复
isNaN Method
Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number).

isNaN(numValue)

The required numValue is the value to be tested against NAN.

Remarks
The isNaN function returns true if the value is NaN, and false otherwise. You typically use this function to test return values from the parseInt and parseFloat methods.

Alternatively, a variable could be compared to itself. If it compares as unequal, it is NaN. This is because NaN is the only value that is not equal to itself.

87,987

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧