2

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

2 Answers 2

1

change it to

(http(s)?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- ;,.\/?%&=]*)?
Sign up to request clarification or add additional context in comments.

Comments

1

You have to assign:

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

And then write:

ng-pattern="{{regex}}"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.