0

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.

<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.

4
  • Remove the last . from regex. Commented Oct 28, 2015 at 5:06
  • @Tushar : Will it take underscore ? Commented Oct 28, 2015 at 5:07
  • No, try ng-pattern="/[a-zA-Z]\d\w{3}/", but this will allow the characters in the same order Commented Oct 28, 2015 at 5:08
  • @Tushar : I used your pattern.But after putting all type character still the error is coming. Commented Oct 28, 2015 at 5:12

1 Answer 1

2

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]).*_.*/"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.