Javascript 输入[电子邮件]的angularjs ng模式不';I don’我没有按预期工作
我想允许任何事情,包括无效电子邮件(无@、空等) 我正在使用:Javascript 输入[电子邮件]的angularjs ng模式不';I don’我没有按预期工作,javascript,angularjs,design-patterns,input,Javascript,Angularjs,Design Patterns,Input,我想允许任何事情,包括无效电子邮件(无@、空等) 我正在使用: ng-pattern="/.*?/" 但除非你不把*@*(比如a@b)输入 如何避免这种情况? <input type="email" ng-pattern="/.*?/" ng-model="email" placeholder="Enter an email here"> 此处type=“email”自行执行验证。如果要允许用户键入任何内容,只需使用常规输入,而不使用type=“email”或ng patte
ng-pattern="/.*?/"
但除非你不把*@*
(比如a@b
)输入
如何避免这种情况?
<input type="email" ng-pattern="/.*?/" ng-model="email" placeholder="Enter an email here">
此处type=“email”
自行执行验证。如果要允许用户键入任何内容,只需使用常规输入,而不使用type=“email”
或ng pattern=“/.*?/”
我使用此指令“绕过”验证程序我无法删除type=“email”,因为它对移动设备很有用(电子邮件输入使用另一个键盘(在主视图中包括“@”字符,等等)我明白。你应该编辑你的问题来添加这个澄清。无论如何,我认为你发布的答案是正确的。
module.directive('ngRemoveEmailValidation', function(){
return {
require : 'ngModel',
link : function(scope, element, attrs, ngModel) {
ngModel.$validators["email"] = function () {
return true;
};
}
}
});