6

I use ng-pattern to validate my client side if a few cases, like looking at password complexity.

Now, I get really strange matches in my regex using ng-pattern. Look at examples down below

<span class="registration-error" ng-show="regForm.password.$error.pattern">- Fail to match..</span>
<input type="password" ng-model="registerForm.password" name="password" ng-pattern="/^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W]).*$/"  required/>

The above should require 8 characters, at least 1 uppercase character and 1 digit or special character. For some reason I get a match on words like FaiLoudD which doesn't make sense.

I run the same regex in my python backend and it works like a charm. I also verified the regex using http://regexpal.com/ and it also works perfect.

Why does ng-pattern match so weird?

Update:

I digged through all modules and the whole building process of my application. The ng-pattern directive started working again when I disabled grunt-html2js in my building process. It seems to have caused ng-pattern to interpret the regex incorrectly. As issue is created at the html2js project. And with that I will close this question.

4
  • 1
    This probably won't fix it, but you should remove the .* from the beginning of the pattern, because you actually want to have all lookaheads start from the beginning of the string (this should also significantly improve performance). Commented Aug 23, 2013 at 8:08
  • Thank m.buettner, did not fix the actual problem but I changed my regex pattern according to your recommendation. Works perfect everywhere except in my client. Ng-pattern still acts really wierd. Commented Aug 23, 2013 at 8:25
  • Looks fine on plnkr.co/edit/1dYysdjfyYilAP7C5DZy?p=preview . Commented Aug 23, 2013 at 9:03
  • Hmm that is really wierd. Yes it works. If I take your code and paste it into my template I get the exact same error. What could possibly disturb ng-pattern to match wrong? I tried to remove all injects and empty my controller to make sure nothing in there did anything but it didnt matter. Same error. Commented Aug 23, 2013 at 9:24

1 Answer 1

5

I digged through all modules and the whole building process of my application. The ng-pattern directive started working again when I disabled grunt-html2js in my building process. It seems to have caused ng-pattern to interpret the regex incorrectly. As issue is created at the html2js project. And with that I will close this question.

Both version 0.1.3 and 0.1.6 of grunt-html2js were tested.

Update

The issue created at the html2js project resulted in version 0.1.7 that resolved the bug. Thank you karlgoldstein for a quick response and fix.

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

1 Comment

It will look a lot more closed if you accept your own answer! :)

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.