-2

There is the following code:

<input class="form-control" id="secret_key" type="text" name="secret_key" ng-model="hotel.secret_key" ng-required="true" ng-minlength="8" placeholder="Secret Key" />

I can validation length of this field, it works. But now I have to validate if this length contains at least one digit, one small letter and one capital letter. How can I do it using AngularJS? Thanks in advance.

malcoauri
  • 11,904
  • 28
  • 82
  • 137

1 Answers1

0

You can set a simple RegExp validation pattern on the input model via ng-pattern as follows:

<input ng-pattern="/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/" name="text" type="text" ng-model="formData">

This will validate that the input contains at least 1 lowercase character, 1 uppercase character and 1 integer.

Here is an example for you to try out the above code.

If you're interested in understanding the RegExp pattern, here is the breakdown.

Community
  • 1
  • 1
Ed B
  • 849
  • 1
  • 7
  • 25