ng-pattern quote escaping

1,696 views
Skip to first unread message

Mark Volkmann

unread,
Aug 13, 2013, 11:37:02 AM8/13/13
to ang...@googlegroups.com
I want to setup validation on a text input so single and double quote characters are not allowed. This works to change single quotes:

ng-pattern="^[^']+$/"

I can't figure out the property syntax to modify this to also check for double quotes. None of these work:

ng-pattern="^[^'"]+$/"
ng-pattern="^[^'\"]+$/"
ng-pattern="^[^'\\"]+$/"

--
R. Mark Volkmann
Object Computing, Inc.

naiJenn suQoro

unread,
May 15, 2015, 11:28:41 AM5/15/15
to ang...@googlegroups.com
This worked for me...
on the controller side define your regex...
$scope.regex = "/^[^\'\"]+$/";


Then on your html you can call...
ng-pattern="{{regex}}"


if you named your controller on html side then you might have to change it to...
ng-pattern="{{name.regex}}"


You were also missing a forward slash at the start of your pattern but escaping single and double quotes does not work well on html side.
Reply all
Reply to author
Forward
0 new messages