我想驗證使用ng-pattern
特定域的電子郵件驗證,可以說,我想這個模式[email protected]
或[email protected]
這是兩個條件,我有當用戶的輸入值適用。我試過emailFromat
以下,但它在所有情況下都顯示無效?任何更好的方法?ng-pattern不適用於特定的電子郵件地址?
main.html中
<div layout="row">
<md-input-container flex="100">
<label>Cc</label>
<input type="email" name="email" ng-model="notifyCtrl.cc" ng-list="," ng-pattern="pattern(user.type)">
<div class="help-block" ng-messages="notifyForm.email.$error" ng-show="notifyForm.email.$touched && notifyForm.email.$invalid">
<div ng-if="user.type === 'notify'">
<div ng-message="pattern">
An email name must only contain a-z, A-Z, 0-9, or _ characters.(ie. [email protected], [email protected]
</div>
</div>
</div>
</md-input-container>
</div>
ctrl.js
var emailFormat = "/^[a-z0-9!#$%&'*+/=?^_`{|}~.-][email protected]+(?: |[a-z0-9-]+\.com|com|[a-z0-9-])$/"
$scope.pattern = function(type){
if(type === 'notify') {
return emailFormat;
}
};
爲什麼它被向下投?我能否收到一些評論? – hussain