0

嗨,我正在使用bootstrapValidator。電子郵件驗證計數此[email protected]有效,而不是[email protected]電子郵件地址的Bootstrap驗證器

<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: [email protected]" 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' 
       } 
      } 
     }, 
    } 
}); 

任何幫助,將不勝感激。

+0

的[驗證在JavaScript中的電子郵件地址是什麼?]可能的複製(http://stackoverflow.com/questions/46155/validate-email-地址在JavaScript) – Tgsmith61591

回答

2

您可以使用regexp驗證程序來定義電子郵件地址的表達式。

regexp: { 
    regexp: '^[^@\\s][email protected]([^@\\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][email protected]([^@\\s]+\\.)+[^@\\s]+$', 
      message: 'The value is not a valid email address' 
     } 
     } 
    }, 
    } 
}); 

Fiddle

+0

非常感謝我,我也加了\ ..第二次最後+,所以它驗證了.com ^ [^ @ \\ s] + @([^ @ \ s] + \ \。)+ \ .. [^ @ \\ s] + $ – Skillie

+0

感謝您的支持!我注意到大寫字母在默認情況下是禁止的,有沒有辦法讓它們通過正則表達式? – Greg