Match two fields with jQuery validate plugin

后端 未结 3 1096
小鲜肉
小鲜肉 2020-12-06 03:52

I have an e-mail field, and a confirm e-mail field. I need to validate both of them to make sure their values match.

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

相关标签:
3条回答
  • 2020-12-06 04:30

    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 讨论(0)
  • 2020-12-06 04:38

    You can also do this on the second field:

     class="required email" equalTo='#email'
    
    0 讨论(0)
  • 2020-12-06 04:53

    You could use the equalTo method:

    $('#myform').validate({
        rules: {
            email: 'required',
            emailConfirm: {
                equalTo: '#email'
            }
        }
    });
    
    0 讨论(0)
提交回复
热议问题