0

I need to validate a password field with pattern matching. I used ng-pattern for that. But it is not working properly.

See this pluker link

The pattern I gave here is, the text should contain at least 8 characters with symbols, alphabets and digits. But when I enter any string the pattern match become true.

See the following code

<body ng-controller="MainCtrl">
    <form name="form">
      <input type="text" name="password" ng-model="user.password" ng-pattern="/(^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[\W]).*$)/">
      <input type="submit">
      {{form.password.$error}}
    </form>
</body>

What am I missing here?

2
  • You should show the code in the question Commented Nov 26, 2013 at 11:47
  • I gave a pluker link. It contains the code. Commented Nov 26, 2013 at 11:56

1 Answer 1

1

This seems to be working. The expression {{form.password.$error}} becomes true if the field is invalid. The empty field does not get validated.

So entering aaaaa (5 letters) makes the field invalid. Adding 1@ (digit+symbol) is still invalid due to length. Adding anything makes it valid (>= 8 characters with letters, digits, symbols → the display says false).

Sign up to request clarification or add additional context in comments.

2 Comments

You mean the regular expression is incorrect doing what the OP describes?
OP writes: "the text should contain at least 8 characters with symbols, alphabets and digits". So 8 letters is invalid indeed.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.