jQuery验证onblur [英] jQuery validation onblur

查看:123
本文介绍了jQuery验证onblur的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使jQuery验证在正在创建的网页上运行.我大约有6个不同的字段集,其中包含页面的详细信息.我正在使用它,因为我要隐藏它们并向他们展示可以提供更好的用户体验.

I am trying to get the jQuery validation working on a webpage I am creating. I have about 6 different fieldsets that contain the page's details. I am using this as I am hiding and showing them give a better user experience.

每当我尝试提交页面和添加单个字符时(当文本框需要2个或更多字符时),我都会根据需要运行插件,但是我也希望在进行模糊验证.我想立即通知我的用户是否不符合验证条件,以便他们可以立即对其进行修复,而不必回来.

I have the plugin working as I want whenever I try submit the page and whenever I add a single character (when a textbox requires 2 or more characters) however I also want the validation to happen onblur. I want to inform my users straight away if they haven't met the validation condition so they can fix it straight away and don't have to come back.

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

Can anyone tell me what I need to do I am using the * http://bassistance.de/jquery-plugins/jquery-plugin-validation/ plugin.

这是我到目前为止编写的jQuery代码:

This is the jQuery code I have written so far:

      $("#aspnetForm").validate({
            rules: {
            <%=txtFirstName.UniqueID %>:
                {
                    required: true,
                    minlength: 2
                }
                ,
                <%=txtSurname.UniqueID %>:
                {
                    required: true,
                    minlength: 2
                }
                ,
                <%=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,
                    minlength:2
                }
                ,
                <%=txtPostCode.UniqueID %>:
                {
                    required: true,
                    minlength:4,
                    maxlength:4
                }

                 ,
                <%=UserName.UniqueID %>:
                {
                    required: true,
                    minlength:4

                }
                ,
                <%=Password.UniqueID %>:
                {
                    required: true,
                    minlength:4

                }
                ,
                 <%=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",
                minlength: "Minimum length is 2 characters"
            },
            <%=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",
                   minlength:"Please add at least 2 characters"
            }
             ,
            <%=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",
                   minlength: "Please add the 4 required characters"

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


            }

           }


        });


有提示吗?


Any tips?

推荐答案

我在docos中看不到任何能做到这一点的东西.我能想到的唯一的其他方法是.

I can't see anything in the docos that can do that. The only other way i can think of doing it is.

$('#field1, #field2, #field3').blur(function(){
    validator.validate()
});

这篇关于jQuery验证onblur的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆