简体   繁体   English

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

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

I need to validate my password field with some special character.This field should contain at least one number,upper case ,lowercase letter and underscore and these are mandotary.I am using ng-pattern and ng-message but failed to do this.I am explaining my code below. 我需要使用一些特殊字符来验证我的密码字段。此字段应至少包含一个数字,大写,小写字母和下划线,这些都是必填项。我正在使用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> 

Here i am not getting any error message.Please help me. 在这里我没有收到任何错误消息。请帮助我。

Field should contain at least one number,upper case ,lowercase letter and underscore and these are mandotary. 字段至少应包含一个数字,大写,小写字母和下划线,这些都是必填项。

You need to use lookahead based regex. 您需要使用基于前瞻的正则表达式。

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

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

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