AngularJS ng-pattern怪异行为(正则表达式)

时间:2022-04-30 11:36:17

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

我使用ng-pattern来验证我的客户端是否有一些情况,比如查看密码复杂性。

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

现在,我使用ng-pattern在我的正则表达式中得到了非常奇怪的匹配。请看下面的例子

<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.

以上应该需要8个字符,至少1个大写字符和1个数字或特殊字符。出于某种原因,我得到像FaiLoudD这样的单词的匹配,这是没有意义的。

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.

我在我的python后端运行相同的正则表达式,它就像一个魅力。我还使用http://regexpal.com/验证了正则表达式,它也很完美。

Why does ng-pattern match so weird?

为什么ng-pattern匹配如此奇怪?

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.

我深入研究了我的应用程序的所有模块和整个构建过程。当我在构建过程中禁用grunt-html2js时,ng-pattern指令再次开始工作。它似乎导致ng-pattern错误地解释了正则表达式。问题是在html2js项目中创建的。有了这个,我将结束这个问题。

1 个解决方案

#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.

我深入研究了我的应用程序的所有模块和整个构建过程。当我在构建过程中禁用grunt-html2js时,ng-pattern指令再次开始工作。它似乎导致ng-pattern错误地解释了正则表达式。问题是在html2js项目中创建的。有了这个,我将结束这个问题。

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

测试了版本0.1.3和0.1.6的grunt-html2js。

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.

在html2js项目中创建的问题导致版本0.1.7解决了该错误。感谢karlgoldstein快速回复并解决问题。

#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.

我深入研究了我的应用程序的所有模块和整个构建过程。当我在构建过程中禁用grunt-html2js时,ng-pattern指令再次开始工作。它似乎导致ng-pattern错误地解释了正则表达式。问题是在html2js项目中创建的。有了这个,我将结束这个问题。

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

测试了版本0.1.3和0.1.6的grunt-html2js。

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.

在html2js项目中创建的问题导致版本0.1.7解决了该错误。感谢karlgoldstein快速回复并解决问题。