-3

We have regex to validate URL. I need a regex that will validate against it. Kindly help me in this.

URL for proper validation

var regexp = /(ftp|http|https)://(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%@!-/]))?/

What's for validating against, i.e it should not be a URL.

1 Answers1

0

Just negate the regex using negative lookahead,

^(?!^((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$).*$

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274