1

嗨,我正在使用 bootstrapValidator。电子邮件验证计数 this emial@emailvalid 而不是emial@email.com.

<div class="col-sm-4 form-group">
   <div class="error-icon">
      <label class="control-label">Email</label>
      <input class="form-control" id="person_email" name="person_email" placeholder="eg: youremail@gmail.com" type="email">
    </div>
</div>

脚本

$('#basicBootstrapForm').bootstrapValidator({ 
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
        person_email: {
            validators: {
               notEmpty: {
                   message: 'The email address is required'
               },
               person_email: {
                   message: 'The input is not a valid email address'
               }
           }
        },
    }
});

任何帮助,将不胜感激。

4

1 回答 1

3

您可以使用regexp验证器来定义电子邮件地址的表达式。

regexp: {
  regexp: '^[^@\\s]+@([^@\\s]+\\.)+[^@\\s]+$',
  message: 'The value is not a valid email address'
}

验证脚本将是

$('#basicBootstrapForm').bootstrapValidator({
  feedbackIcons: {
    valid: 'glyphicon glyphicon-ok',
    invalid: 'glyphicon glyphicon-remove',
    validating: 'glyphicon glyphicon-refresh'
  },
  fields: {
    person_email: {
      validators: {
        notEmpty: {
          message: 'The email address is required'
        },
        regexp: {
          regexp: '^[^@\\s]+@([^@\\s]+\\.)+[^@\\s]+$',
          message: 'The value is not a valid email address'
        }
      }
    },
  }
});

小提琴

于 2016-04-11T23:52:02.380 回答