jQuery验证onblur

前端之家收集整理的这篇文章主要介绍了jQuery验证onblur前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在我创建的网页上进行jQuery验证。我有大约6个不同的字段集,其中包含页面的详细信息。我正在使用它,因为我隐藏,并显示他们给更好的用户体验。

只要我尝试提交页面,并且每当我添加一个字符(当一个文本框需要2个或更多的字符)时,我都可以使用插件),但是我也希望验证发生在onblur上。如果他们没有达到验证条件,我们可以立即通知我的用户,以便他们可以立即修复它,而不必再回来。

任何人都可以告诉我我需要做什么我正在使用* http://bassistance.de/jquery-plugins/jquery-plugin-validation/插件

这是迄今为止我写的jQuery代码

$("#aspnetForm").validate({
            rules: {
            <%=txtFirstName.UniqueID %>:
                {
                    required: true,minlength: 2
                },<%=txtSurname.UniqueID %>:
                {
                    required: true,<%=txtMobileNumber.UniqueID %>:
                {
                    required: true,minlength: 8
                },<%=Email.UniqueID %>:
                {
                    required: true,email: true
                },<%=ddDay.UniqueID %>:
                {
                    required: true

                },<%=ddMonth.UniqueID %>:
                {
                    required: true

                },<%=ddYear.UniqueID %>:
                {
                    required: true

                },<%=txtHouseNumber.UniqueID %>:
                {
                    required: true,minlength:1

                },<%=txtAddress1.UniqueID %>:
                {
                    required: true,minlength:5
                },<%=txtCity.UniqueID %>:
                {
                    required: true,minlength:2
                },<%=txtSuburb.UniqueID %>:
                {
                    required: true,<%=txtPostCode.UniqueID %>:
                {
                    required: true,minlength:4,maxlength:4
                },<%=UserName.UniqueID %>:
                {
                    required: true,minlength:4

                },<%=Password.UniqueID %>:
                {
                    required: true,<%=ConfirmPassword.UniqueID %>:
                {
                   equalTo: "ctl00$ctl00$cpMain$cpLeft$Password"

                },<%=chkTerms.UniqueID %>:
                {
                    required: true


                }

            },messages: {
                <%=txtFirstName.UniqueID %>:
            {
                required: "Please enter your firstname",minlength: "Minimum length is 2 characters"
            },<%=txtSurname.UniqueID %>:
            {
                required: "Please enter your lastname",<%=txtMobileNumber.UniqueID %>:
            {
                required: "Please enter your mobile",minlength: "Minimum length is 8 characters"
            },<%=ddDay.UniqueID %>:
            {
                required: "Please enter your date of birth"

            },<%=txtMobileNumber.UniqueID %>:
            {
                  required: "Please enter your date of birth"
            },<%=txtMobileNumber.UniqueID %>:
            {
                   required: "Please enter your date of birth"
            },<%=Email.UniqueID %>: 
                  "Please enter a valid email",<%=txtHouseNumber.UniqueID %>:
            {
                   required: "Please enter your house number",minlength:"Please add at least 1 character"
            },<%=txtAddress1.UniqueID %>:
            {
                   required: "Please enter your address",minlength:"Please add at least 5 characters"
            },<%=txtCity.UniqueID %>:
            {
                   required: "Please enter your city",minlength:"Please add at least 2 characters"
            },<%=txtSuburb.UniqueID %>:
            {
                   required: "Please enter your city",<%=txtPostCode.UniqueID %>:
            {
                   required: "Please enter your postcode",minlength:"Please add the 4 required characters",maxlength:"Only 4 characters are allowed"
            },<%=UserName.UniqueID %>:
            {
                   required: "Please enter your username",minlength: "Please add the 4 required characters"

            },<%=Password.UniqueID %>:
            {
                   required: "Please enter your password",<%=ConfirmPassword.UniqueID %>:
            {
                  equalTo: "Passwords must match"
             },<%=chkTerms.UniqueID %>:
            {
                   required: "Please agree to the terms"


            }

           }


        });

任何提示

解决方法

我看不到docos中可以做到的任何事情。唯一的其他方式我可以想到这样做。
$('#field1,#field2,#field3').blur(function(){
    validator.validate()
});

猜你在找的jQuery相关文章