[英]AngularJS - input for name or email, How to implement?
How to to implement validation for input:如何实现输入验证:
That if there is no @
so it's a name.如果没有
@
那么它就是一个名字。 and should be a minimum of 3 characters.并且至少应为 3 个字符。
And if there have @
- so it's a Email.如果有
@
- 所以它是一个电子邮件。 and he must to be a valid Email他必须是一个有效的电子邮件
I'm trying to think of a way how to do it and I can not find我正在想办法怎么做,但我找不到
I want to show the errors based on我想显示基于的错误
ie: If no @
- error would be only for a minimum characters即:如果没有
@
- 错误只会出现最少字符
And if there @
- Error will be for a valid email如果有
@
- 错误将是一个有效的电子邮件
<input type="email"
ng-model="string"
[name="string"]
[required="string"]
[ng-required="string"]
[ng-minlength="number"]
[ng-maxlength="number"]
[pattern="string"]
[ng-pattern="string"]
[ng-change="string"]>
<input name="email" type="email" ng-model="obj.email" ng-pattern="/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/" required>
There is excellent documentation + examples are provided on AngularJs official site. AngularJs 官方网站上提供了优秀的文档和示例。
Check input directive and customize them according to your need:检查输入指令并根据需要自定义它们:
<input
ng-model="string"
[name="string"]
[required="string"]
[ng-required="boolean"]
[ng-minlength="number"]
[ng-maxlength="number"]
[ng-pattern="string"]
[ng-change="string"]
[ng-trim="boolean"]>
...
</input>
For input[email]
用于
input[email]
<input type="email"
ng-model="string"
[name="string"]
[required="string"]
[ng-required="string"]
[ng-minlength="number"]
[ng-maxlength="number"]
[pattern="string"]
[ng-pattern="string"]
[ng-change="string"]>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.