AngularJS ng-pattern weird behavior (regex)

I use ng-pattern to check my client side, if in several cases, for example, given the complexity of the password.

Now I get really strange matches in my regex using ng-pattern. See examples 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,})(?=.*[az])(?=.*[AZ])(?=.*[\d\W]).*$/" required/> 

The above should contain 8 characters, at least 1 uppercase character and 1 character or special character. For some reason, I get a match for words like FaiLoudD , which makes no sense.

I run the same regular expression in my python backend and works like a charm. I also checked the regex using http://regexpal.com/ and it also works great.

Why does ng-pattern match so weird?

Update:

I dug up all the modules and the entire build process of my application. The ng-pattern directive started working again when I disabled grunt-html2js in my build process. Ng-pattern seems to misinterpret the regular expression. Since the problem is being created in the html2js project. And with that I will close this question.

+6
source share
1 answer

I dug up all the modules and the entire build process of my application. The ng-pattern directive started working again when I disabled grunt-html2js in my build process. Ng-pattern seems to misinterpret the regular expression. Since the problem is being created in the html2js project. And with that I will close this question.

Both versions 0.1.3 and 0.1.6 from grunt-html2js were tested.

Update

The problem created in the html2js project led to version 0.1.7, which resolved the error. Thanks to karlgoldstein for the quick response and correction.

+5
source

Source: https://habr.com/ru/post/952341/


All Articles