ad " and ' inside ng-pattern html

97 Views Asked by At

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 ?

1

There are 1 best solutions below

0
Tim Biegeleisen On

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}}"