繁体   English   中英

无法使用angular.js使用reg exp验证密码字段

[英]Can not validate password field with reg exp using angular.js

我需要使用一些特殊字符来验证我的密码字段。此字段应至少包含一个数字,大写,小写字母和下划线,这些都是必填项。我正在使用ng-patternng-message但操作失败。在下面解释我的代码。

<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Password :</span>
<div ng-class="{ 'has-error': billdata.pass.$touched && billdata.pass.$invalid }">
<input type="{{inputType}}" name="pass" id="contactno" class="form-control" placeholder="password" ng-model="password" ng-minlength="8" ng-pattern="/[a-zA-Z][0-9][a-zA-Z0-9]{3}/." >
</div>
</div>
<div class="help-block" ng-messages="billdata.pass.$error" ng-if="billdata.pass.$touched">
<p ng-message="minlength" style="color:#F00;">This field is too short.The min length of your password should be 8.</p>
<p ng-message="pattern" style="color:#F00;">This field needs the special character like number,upper case,lower case letter,underscore.</p>
</div> 

在这里我没有收到任何错误消息。请帮助我。

字段至少应包含一个数字,大写,小写字母和下划线,这些都是必填项。

您需要使用基于前瞻的正则表达式。

ng-pattern="/^(?=.*[A-Z])(?=.*\d)(?=.*[a-z]).*_.*/"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM