开发者

Match two fields with jQuery validate plugin

开发者 https://www.devze.com 2023-02-14 04:07 出处:网络
I have an e-mail field, and a confirm e-mail field. I need to validate both of them开发者_JAVA百科 to make sure their values match.

I have an e-mail field, and a confirm e-mail field. I need to validate both of them开发者_JAVA百科 to make sure their values match.

Is there a way to add a rule to match those two fields?


You could use the equalTo method:

$('#myform').validate({
    rules: {
        email: 'required',
        emailConfirm: {
            equalTo: '#email'
        }
    }
});


You can also do this on the second field:

 class="required email" equalTo='#email'


U can use this

email: {
      required: true, email: true
      },
c_email: { 
                required: true, equalTo: "#email", minlength: 5
          },

<div class="form-row"><span class="label">email</span><input type="email" name="email" class="required" id="email" /></div>

<div class="form-row"><span class="label">Confirm email</span><input type="email" name="c_email" id="c_email" /></div>
0

精彩评论

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