Reputation: 981
I have a regex pattern as (http(s)?://)?([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?
which is working fine if I use some online tool to check it but when i use it in ng-pattern as ng-pattern="(http(s)?://)?([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?"
it is throwing error?
Invalid regular expression: /^(http(s)?://)?([w-]+.)+[w-]+(/[w- ;,./?%&=]*)?$/: Range out of order in character class
I have searched many questions over this issue but none seems to be working
Upvotes: 2
Views: 435
Reputation: 1313
You have to assign:
$scope.regex = "(http(s)?://)?([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?";
And then write:
ng-pattern="{{regex}}"
Upvotes: 1
Reputation: 1718
change it to
(http(s)?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- ;,.\/?%&=]*)?
Upvotes: 1