非数字验证(Javascript)

1.非数字验证:

var i = document.getElementById('xxid').value;
if (!isNaN(i))
{
   alert("字符必须为整数!");
   return false;
}

2.输入连续的整正数验证(利用正则表达式):
    <script language="javascript">
        function NumberValidate(obj)
        {
            if(obj.value=="")
            {
                alert("请输入数字");
                return false;
            }
            else
            {
                if(/^\d*$/.test(obj.value))
                {
                    return true;
                }
                else       
                {               
                    alert("只能是数字,请重新输入!");               
                    obj.select();               
                    return false;       
                }
            }
        }
       
    </script>

posted @ 2010-03-18 21:13  StarWang  阅读(263)  评论(0编辑  收藏  举报