if(isNaN(value))
  不是数字
else
  是数字

解决方案 »

  1.   

    那我下面这个程序错在哪里了?<HTML>
    <HEAD>
    <META name=VI60_defaultClientScript content=JavaScript>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <TITLE></TITLE>
    <SCRIPT LANGUAGE=javascript>
    <!--
    function che() {
    if (!isNaN(123)) {
    window.alert("数字")
    else
    window.alert("不是数字")
    }
    }
    //-->
    </SCRIPT></HEAD>
    <BODY>
    <INPUT type="button" value="Button" id=button1 name=button1 onclick="che()"></BODY>
    </HTML>
      

  2.   

    function che() 
    {
    if (!isNaN(123))
       window.alert("数字")
    else
       window.alert("不是数字")
    }
      

  3.   

    多谢这位兄台,可否帮我看一下,下面这段程序有什么错误?
    这段程序是来判断表单填写的生日是否合法。谢谢!
    function checkForm(theForm) {
    if ((!theForm.dtBirthYearGet.value) && (!theForm.dtBirthMonthGet.value) && (!theForm.dtBirthDayGet.value)) {
    if (!isNaN(theForm.dtBirthYearGet.value) && (!isNaN(theForm.dtBirthMonthGet.value) && (!isNaN(theForm.dtBirthDayGet.value)) {
    if (((theForm.dtBirthYearGet.value <= 1900) || (theForm.dtBirthMonthGet.value >= 2002)) || ((theForm.dtBirthMonthGet.value <=1) || (theForm.dtBirthMonthGet.value >= 12)) || ((theForm.dtBirthDayGet.value <= 1) || (theForm.dtBirthDayGet.value >= 31))) { 
    window.alert ("您的生日填写有错误."); 
    theForm.dtBirthYearGet.focus();
    return(false);
    }
    else 
    window.alert ("您的生日填写有错误.");
    theForm.dtBirthYearGet.focus();
    return(false);
    }
    }
    }下面有一个这样的表单。
    <form ...... name=form onsubmit="return checkForm(form)">
      

  4.   

    你的程序是不是总是报错,即  ("您的生日填写有错误.");
    如果是的话,我试了一下
    你的else没有指定正确位置,即根据就近原则它和最后一个if配对
    所以不管你的if后面的条件是否为真,都会执行
    window.alert ("您的生日填写有错误."); 
    theForm.dtBirthYearGet.focus();
    return(false);
    因为if 和else一样的
    如果你有良好的编程习惯的话(缩进编辑,配对括号),你会很清楚
    的发现问题所在。修改后如下(仅供参考)function checkForm(theForm)
    {
    if ((!theForm.dtBirthYearGet.value) && (!theForm.dtBirthMonthGet.value) && (!theForm.dtBirthDayGet.value)) 
        {
    if (!isNaN(theForm.dtBirthYearGet.value) && (!isNaN(theForm.dtBirthMonthGet.value) && (!isNaN(theForm.dtBirthDayGet.value)) 
            {
    if (((theForm.dtBirthYearGet.value <= 1900) ||(theForm.dtBirthMonthGet.value >= 2002)) || ((theForm.dtBirthMonthGet.value <=1) || (theForm.dtBirthMonthGet.value >= 12)) || ((theForm.dtBirthDayGet.value <= 1) || (theForm.dtBirthDayGet.value >= 31)))
                   { 
         window.alert ("您的生日填写有错误."); 
         theForm.dtBirthYearGet.focus();
         return(false);
    }
            }
    else

    window.alert ("您的生日填写有错误.");
    theForm.dtBirthYearGet.focus();
    return(false);
    }
        }
    }
      

  5.   

    <SCRIPT LANGUAGE="JavaScript"><!-- function AbortEntry(sMsg, eSrc)
     {
      window.alert(sMsg);
      // set focus and highlight to the offending error
      eSrc.focus();
      eSrc.select();
     }
    function HandleKeyUp(eSrc)
     {
      // make sure they input a numeric value
      // (in VBScript you'd use the IsNumeric() function)
      var val = parseInt(eSrc.value);
      if (isNaN(val))
      {
       return AbortEntry("Must be a number.", eSrc);
      }  // make sure the value is in range
      if (val < 0 || val > 255) 
      {
       return AbortEntry("Value must be between 0 and 255.", eSrc);
      }
     }
    //--></SCRIPT>
    Please enter a valid IP address
    <FORM>
    <INPUT TYPE="text" size=3 maxlength=3 ONKEYUP="HandleKeyUp(this)">.
    <INPUT TYPE="text" size=3 maxlength=3 ONKEYUP="HandleKeyUp(this)">.
    <INPUT TYPE="text" size=3 maxlength=3 ONKEYUP="HandleKeyUp(this)">.
    <INPUT TYPE="text" size=3 maxlength=3 ONKEYUP="HandleKeyUp(this)">
    </FORM>
      

  6.   

    判断是不是数字要这么麻烦?for (var i=0;i<string.length;i++)
    {
        if (string.charAt(i)>'9' && string.charAt(i)<'0') alert("is number");
        else alert("is not number");
    }try this!
      

  7.   

    谢谢各位,但是问题还是没有解决,哪位可以帮我改改这个程序。
    这段程序是来判断表单填写的生日是否合法。谢谢!
    function checkForm(theForm) {
    if ((!theForm.dtBirthYearGet.value) && (!theForm.dtBirthMonthGet.value) && (!theForm.dtBirthDayGet.value)) {
        if (!isNaN(theForm.dtBirthYearGet.value) && (!isNaN(theForm.dtBirthMonthGet.value) && (!isNaN(theForm.dtBirthDayGet.value)) {
            if (((theForm.dtBirthYearGet.value <= 1900) &brvbar;&brvbar; (theForm.dtBirthMonthGet.value >= 2002)) &brvbar;&brvbar; ((theForm.dtBirthMonthGet.value <=1) &brvbar;&brvbar; (theForm.dtBirthMonthGet.value >= 12)) &brvbar;&brvbar; ((theForm.dtBirthDayGet.value <= 1) &brvbar;&brvbar; (theForm.dtBirthDayGet.value >= 31))) { 
                window.alert ("您的生日填写有错误."); 
                theForm.dtBirthYearGet.focus();
                return(false);
    }
            else 
                window.alert ("您的生日填写有错误.");
                theForm.dtBirthYearGet.focus();
                return(false);
                }
    }
    }下面有一个这样的表单。
    <form ...... name=form onsubmit="return checkForm(form)"> 
      

  8.   

    根本就不用判断是不是输入的是数字,直接象下面这样写就行了:
    function checkForm(theForm) {
    if ((!theForm.dtBirthYearGet.value) && (!theForm.dtBirthMonthGet.value) && (!theForm.dtBirthDayGet.value)) {
            if (((theForm.dtBirthYearGet.value <= 1900) &brvbar;&brvbar; (theForm.dtBirthMonthGet.value >= 2002)) &brvbar;&brvbar; ((theForm.dtBirthMonthGet.value <=1) &brvbar;&brvbar; (theForm.dtBirthMonthGet.value >= 12)) &brvbar;&brvbar; ((theForm.dtBirthDayGet.value <= 1) &brvbar;&brvbar; (theForm.dtBirthDayGet.value >= 31))) { 
                window.alert ("您的生日填写有错误."); 
                theForm.dtBirthYearGet.focus();
                return(false);
    }
            else {
                window.alert ("您的生日填写有错误.");
                theForm.dtBirthYearGet.focus();
                return(false);
                }
    }
    }对了,你的程序里面好像括号不配对,看看是不是这个地方错?
      

  9.   

    可以根据keyCode来判断。
    if(((event.keyCode>=48)&&(event.keyCode<=57))||((event.keyCode>=96)&&(event.keyCode<=105)))
    {
       alert("该字符为数字!");
    }
    说明:其中48到57为小键盘0到9十个数字;
         96到105为数字0到9十个字符
      

  10.   

    我想把这个函数写到js文件里面。
    Vbscript可不可以像javascript写成一个js文件呢?