I know ng-pattern can be used to allow characters. I'm looking for a way to just limit one specific character.
My input box should work with any characters except the verticle bar '|' . I want to either throw an error just not allow it to be typed out. Is there an easy way to just not allow that specific character. Or should I just use ng-pattern to include EVERYTHING except the vertical bar? ( how would I do that?)
You need to add an
ng-pattern attribute to the
input and use a regex that will restrict textual input.
This regex must match the text, thus, you need to check if the full input has no pipe symbols.
^- start of string
[^|]*- zero or more symbols other than
+to disallow empty input)
$- end of string.
/.../ are regex delimiters that will let angular know we are passing a regex object rather than a string.
ng-pattern="[^|]*" should also work since string patterns are anchored by default in Angular.