function checkAge(form) /* for age validation */
{
var eobj=document.getElementById('ageerror');
var age = form.age.value;
var oR =/[0-9,.]+/;
eobj.innerHTML='';
if (age == '') {
error='Error: Age cannot be blank!';
form.age.focus();
}
else if (!oR.test(age))
{
error='Incorrect format!'
}
if (error)
{
form.age.focus();
eobj.innerHTML=error;
return false;
}
}
- var oR =/[0-9,.]+/;
- 否则如果(!oR.test(年龄))
这部分有什么错误吗?
希望有人能帮我解决问题,谢谢!
最佳答案
添加
var error;
在您的函数开始处,以便重新初始化错误。
现在,由于变量是全局变量,如果它失败一次就永远不会被清除。
关于javascript - 当我输入 numeric 时,它也将其检测为不正确的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18577939/