0

Can't seem to get this to work. Trying to do a confirm email bootstrap validator. The original email validator works but not the second. Not sure what I'm missing.

   <div class="form-group">
      <div class="col-md-11">
         <label for="inputEmail" class="sr-only">Enter Email</label>
         <input type="email" class="form-control" placeholder="Enter Email" id="email" name="email" size="35" required/>
         <div class="help-block with-errors"></div>
         <span class="glyphicon form-control-feedback" id="email1"></span>
     </div>
     </div>
     <div class="form-group">
         <div class="col-md-11">
            <input type="email" class="form-control" name="emailConfirmed" placeholder="Confirm Email" id="emailConfirmed" size="35" />
     </div>
 </div>

$('#form').validate({
    fields: {
        email: {
            minlength: 3,
            required: true,
            validators: {
                notEmpty: {
                    message: 'The confirm email is required and cannot be empty'
                },
                identical: {
                    field: 'emailConfirmed',
                    message: 'The email and its confirm are not the same'
                }
            }
        },
        emailConfirmed: {
            validators: {
                notEmpty: {
                    message: 'The confirm email is required and cannot be empty'
                },
                identical: {
                    field: 'email',
                    message: 'The email and its confirm are not the same'
                }
            }
        }
    }
 });
Keith
  • 4,059
  • 2
  • 32
  • 56
  • What library for validation are you using? – Steven B. Jun 07 '17 at 19:24
  • Possible duplicate of [Match two fields with jQuery validate plugin](https://stackoverflow.com/questions/5147438/match-two-fields-with-jquery-validate-plugin) – Jeevan Jun 07 '17 at 19:24

1 Answers1

2

You could use the equalTo method:

$('#myform').validate({
    rules: {
        email: 'required',
        emailConfirm: {
            equalTo: '#email'
        }
    }
});
Jeevan
  • 317
  • 4
  • 18