Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS ng-pattern weird behavior (regex)

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.

like image 442
JoakimB Avatar asked Aug 23 '13 07:08

JoakimB


1 Answers

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.

like image 155
JoakimB Avatar answered Sep 28 '22 02:09

JoakimB