Green_qaue
Green_qaue

Reputation: 3661

Adding to regex, dont allow certain characters

I have a regex that does not allow an url to start with http, and foreces it to start with www. Now I would like to add to it so it does not allow any special characters.

Current regex: ^(?!https?)www\..*$

Characters I do not want to allow: !"@#£¤$%&/{([)]=}?+`´*'

I'm using ASP.NET.

I've tried using negated characters for ex: [^%!] to not allow % and !, but can't get it to work, it just checks the first character of the word.

Upvotes: 1

Views: 85

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174696

Use a negative lookahead assertion at the start which includes the list of characters you want to exclude.

^(?!.*?[!"@#£¤$%&\/{(\[)\]=}?+\\`´*'])(?!https?)www\..*$

Upvotes: 2

Related Questions