更新时间:2022-06-12 21:16:13
您应该使用 NG-要求
和 NG-模式
上的电子邮件输入字段。
You should use ng-required
and ng-pattern
on the email input field.
<input type="text" ng-model="email" ng-required="emailRequired" ng-pattern="emailPattern" />
和再定义 emailPattern
作为对 $范围功能
您的控制器。
And then define emailPattern
as function on the $scope
of your controller.
$scope.emailPattern = (function() {
var regexp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return {
test: function(value) {
if( $scope.emailRequired === false ) return true;
else return regexp.test(value);
}
};
})();
下面拨弄实现你想要什么:
The following fiddle implements what you want: