【问题标题】:Validation of 3-d type password using angular.js使用 angular.js 验证 3-d 类型密码
【发布时间】:2015-10-27 09:41:45
【问题描述】:

我有一个密码字段,该字段应包含一个字母、数字、一个大写字母和一个不带空格且最少 8 个字符长度的特殊字符。如何使用 angular.js 验证这一点? 我的代码如下:

<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Password :</span>
<input type="{{inputType}}" name="itemname" id="contactno" class="form-control" placeholder="password" ng-model="password" >

在我的一些代码中,我使用ng-message 来检查电子邮件和用户名等验证。

【问题讨论】:

  • 您是否需要针对特定​​错误的特定错误消息? Like : 至少需要一个数字。

标签: javascript angularjs forms validation


【解决方案1】:

使用 ng-pattern 并找到合适的正则表达式

<input type="{{inputType}}" name="itemname" id="contactno" class="form-control" placeholder="password" ng-model="password" ng-pattern="/[a-zA-Z]{4}[0-9]{6,6}[a-zA-Z0-9]{3}/.">

这是示例正则表达式,你应该找到一个接受你的标准的

【讨论】:

  • @Bleja:我需要知道如何使用这个示例?
  • 我更新了答案,如果输入值不匹配 ng-pattern 它将无效。您可以使用 invalid user name 或显示 ng-messages 显示消息
  • parentForm 是包含此输入的表单的名称
  • 并且你不应该使用 HMLT 验证,比如 type=email 如果你正在使用 ng-pattern
  • 你需要在表单中添加 novalidate 指令。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-25
  • 2017-05-31
  • 1970-01-01
  • 2014-08-09
  • 2020-12-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多