简体   繁体   English

AngularJS中的ng-Pattern用于仅显示三个显示解析错误的特殊字符

[英]ng-Pattern in AngularJS for exculding just three special characters showing a parsing error

Firstly, without the ng-pattern attribute there is no error at all, so it is safe to say that the problem is only in regards to the ng-pattern. 首先,没有ng-pattern属性根本没有错误,因此可以肯定地说问题仅在ng-pattern方面。 I changed the patternExcludes variable multiple times, for instance 例如,我多次更改了patternExcludes变量

  • [^\\s\\$\\^]+
  • /[^\\s\\$\\^]/
  • /^[^\\s\\$\\^]$/

and many other variations of these that I can think of. 以及我能想到的其他许多变化。 With the regex being [^\\ \\$\\^]+ the ng-message is featered correctly but the issues is that in the Console in Chrome I get a Error: $parse:lexerr Lexer Error . 正则表达式为[^\\ \\$\\^]+ ,可以正确完成ng-message,但问题是在Chrome的Console中,我得到一个Error: $parse:lexerr Lexer Error All other variations do not work, some hide/ignore the parsing error. 所有其他变体均不起作用,有些隐藏/忽略了解析错误。

In the Auth Controller 在验证控制器中

patternExcludes = "[^\ \$\^]+";

// pattern automatically is wrapped with '/^' and '$/'
$scope.passwordPattern = patternExcludes;

In signup.html 在signup.html中

<input data-ng-model="Password" data-ng-minlength="8" data-ng-maxlength="32" name="Password"
                           type="password" class="form-control" placeholder="Password"
                           ng-pattern="{{passwordPattern}}" required>

Also in signup.html 也在signup.html中

<div ng-messages="SignUpForm.Password.$error" ng-if="SignUpForm.Password.$dirty"
                         class="msgColor" role="alert">
                        <!--... omitted ng-messages-->
                        <div ng-message="pattern">Your Password must <strong>NOT</strong> contain special characters</div>
                    </div>

Try removing the {{}} from around passwordPattern. 尝试从passwordPattern附近删除{{}}。

https://docs.angularjs.org/api/ng/directive/ngPattern https://docs.angularjs.org/api/ng/directive/ngPattern

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM