簡體   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