0

I have a ng pattern like this ^[^#'"/]+$ to not allow the use of / " ' and #

i would like to add it inside the ng-pattern='/^[^#'"/]+$/' bug since there is the " and ' it break my string, and any attempt I made to fix this, it doesn't work.

How can I achieve it ?

Bobby
  • 4,372
  • 8
  • 47
  • 103

1 Answers1

0

One option would be to define the regex in your controller:

$scope.regex = "/^[^#'\"/]+$/";

Note that we only have to escape the double quote. Then, apply it in the HTML element which is using ng-pattern:

ng-pattern="{{regex}}"
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360