【问题标题】:identical email bootstrap validation相同的电子邮件引导验证
【发布时间】:2017-11-09 06:47:09
【问题描述】:

似乎无法让它工作。尝试做一个确认电子邮件引导验证器。原始电子邮件验证器有效,但第二个无效。不知道我错过了什么。

   <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'
                }
            }
        }
    }
 });

【问题讨论】:

标签: jquery twitter-bootstrap


【解决方案1】:

您可以使用equalTo 方法:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多