问题描述
我使用的角度表单验证。
I am using Angular for form validation.
下面是我使用 - 我采取这种code从Angularjs文档 - 曾用类型电子邮件
但是当我运行这一点,并输入 ABC @ ABC
它说,它是有效的。我该如何解决这个问题?
Here is what I use - plunker-edit I have taken this code from Angularjs documentation - Binding to form and control state Have used type as email
but when I run this and enter abc@abc
it says it is valid. How do I fix this ?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-example100-production</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.8/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="">
<div ng-controller="Controller">
<form name="form" class="css-form" novalidate>
E-mail:
<input type="email" ng-model="user.email" name="uEmail" required/><br />
<div ng-show="form.uEmail.$dirty && form.uEmail.$invalid">Invalid:
<span ng-show="form.uEmail.$error.required">Tell us your email.</span>
<span ng-show="form.uEmail.$error.email">This is not a valid email.</span>
</div>
</form>
</div>
</body>
</html>
P.S:我在AngularJs初学者
P.S : I am a beginner in AngularJs
编辑:
还有以下输入WER也显示有效。
Also the following inputs wer also shown valid
- AAA @ AAA
- AAA --- [email protected]
- aaa`aaa @ AAA
预计的有效电子邮件
推荐答案
请参考我的另一个答案:的
Refer to my another answer: AngularJS v1.3.x Email Validation Issue
试着在你的电子邮件输入使用NG-模式。
Try to use ng-pattern in your email input.
<input type="email" name="input" ng-model="text" ng-pattern="/^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/" required>
它适合你的有效和无效的案件。
It fits your valid and invalid cases.
见一个例子:
这篇关于表单验证 - 电子邮件验证未正常工作的AngularJs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!