Ng-pattern must not match the given pattern

In ng-patternwe have the opportunity to indicate that the field should match a specific template.

How can we indicate that it should NOT match the specified pattern?

Example

<input type="text" ng-pattern="/[*|\":<>[\]{}`()';@&$]/" />

Here I do NOT want the field to match the pattern. On the contrary, I want to show an error if the pattern matches.

+4
source share
2 answers

To check if a string contains any substring, you can use string binding with a string:

/^(?!.*[*|\x22:<>[\]{}`()';@&$])/

Watch the demo

AngularJS , RegExp ( ), ( , ).

, ^(?:(?![*|\x22:<>\[\]{}`()';@&$]).)*$ (. demo), , .

, \x22 ng-pattern.

+1

((?!pattern)), :

ng-pattern="/(?![*|\":<>[\]{}`()';@&$])/"
+2

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


All Articles