$(document).ready(function() {
var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
$('#submit').click(function() {
var $email=$('#email');
valid = true;
errorMessage = "";
if (valid && $('#name').val() == '') {
errorMessage="please enter your name \n";
valid = false;
e.preventDefault();
}
if (valid && $('#pwd').val() == '') {
errorMessage+="please enter your password \n";
valid =false;
e.preventDefault();
}
if (valid && $('#mobile').val() == '') {
errorMessage+="please enter your mobile number \n";
valid = false;
e.preventDefault();
}
if (valid && $('#presentaddress').val() == '') {
errorMessage+="please enter your residential address \n";
valid = false;
e.preventDefault();
}
if (valid && $('#drivinglicense').val() == '') {
errorMessage+="please enter your driving license number \n";
valid = false;
e.preventDefault();
}
if (valid && $email.val() == '') {
errorMessage+="please enter your email \n";
valid = false;
e.preventDefault();
}
if(valid && $email.val() !== ""){
if(!pattern.test($email.val())){
errorMessage="Please enter email in correct format \n";
valid = false;
e.preventDefault();
}
}
if( !valid && errorMessage.length > 0){
alert(errorMessage);
}
});
});
我已经正确验证了我的js并且我的js被正确调用错误是在这个jquery文件中有人可以让我知道我在这个jquery循环验证中哪里出错了我应该返回有效的某些地方,有些人指导我更好地了解< / p>
答案 0 :(得分:0)
每当条件变为假并且你想在需要时停止jquery执行do return false
时,我必须告诉你,这是处理if条件验证的正确方法。