用于电子邮件地址的Bootstrap Validator

时间:2016-04-11 18:20:12

标签: javascript twitter-bootstrap validation jqbootstrapvalidation bootstrapvalidator

您好我正在使用bootstrapValidator。电子邮件验证会将此emial@email设为有效而非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'
               }
           }
        },
    }
});

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

您可以使用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'
        }
      }
    },
  }
});

Fiddle