function validator()
{
var f = document.forms.suform.elements.fn.value;
if(f==null || f=="" || f==" ") //condition 1
{
alert("First name is required!");
return false;
}
else if(!(/^[a-zA-Z ]{2,30}$/,test(f))) // condition 2
{
alert('Invalid First Name');
return false;
}
//Some other conditions
}
我称之为
<form method="post" name="suform" onsubmit="return validator()" action="register.php">
<input placeholder="First Name" name="fn" type="text" id="fname" maxlength=20>
//other inputs
</form>
现在问题是条件2不起作用,只要它在那里,它下面的条件也不起作用, 第二个我删除条件2一切都开始运行正常。 正则表达式检查中存在一些错误。
答案 0 :(得分:0)
(/^[a-zA-Z ]{2,30}$/.test(f))
时间段将在测试前发生()