开发者

jquery on blur validation

I am using jquery validation plugin. Here after click the "submit" button, my form gets validated. But i need onblur validation, for ex: if the html textbox/other elemets lost their focus(onblur) then i need to validate the corresponding field. so How do I modify the below code?

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript" >
$(document).ready(function() {
$.validator.addMethod("email", function(value, element)
{
return this.optional(element) || /^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/i.test(value);
}, "Please enter a valid email address.");

$.validator.addMethod("开发者_开发知识库username",function(value,element)
{
return this.optional(element) || /^[a-zA-Z0-9._-]{3,16}$/i.test(value);
},"Username are 3-15 characters");

$.validator.addMethod("password",function(value,element)
{
return this.optional(element) || /^[A-Za-z0-9!@#$%^&*()_]{6,16}$/i.test(value);
},"Passwords are 6-16 characters");

// Validate signup form
$("#signup").validate({
rules: {
email: "required email",
username: "required username",
password: "required password",
},
});
});
</script>

Thanks in advance


According to the docs, you enable validation when inputs lose focus with onfocusout:

$(".selector").validate({
    onfocusout: false
})

In your case, specifically:

$("#signup").validate({
    onfocusout: false,    //this setting is what you need
    rules: {
        email: "required email",
        username: "required username",
        password: "required password"
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜