abhit
abhit

Reputation: 981

ng-pattern not working in angular js

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

Answers (2)

Rahi.Shah
Rahi.Shah

Reputation: 1313

You have to assign:

$scope.regex = "(http(s)?://)?([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?";

And then write:

ng-pattern="{{regex}}"

Upvotes: 1

Vikash Kumar
Vikash Kumar

Reputation: 1718

change it to

(http(s)?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- ;,.\/?%&=]*)?

Upvotes: 1

Related Questions