0

Overview:

I'm using this regex in server side C# validation code. Now I need to implement the same regex in javascript on the client side. When I define the regex in js the compiler throws syntax errors on the pattern stating there are invalid characters.

var urlValidationRegex = /(https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?$/;

Resolution Steps:

I tried adding a / to the start and end of the regex pattern, but that throws further syntax errors.

Question:

How can i convert this regex to a javascript equivalent?

Brian Var
  • 6,029
  • 25
  • 114
  • 212
  • You have ``/`` inside, escape them, too: [`/(https?|ftp):\/\/(-\.)?([^\s/?.#-]+\.?)+(\/[^\s]*)?$/`](https://regex101.com/r/cW0jI4/1) – Wiktor Stribiżew Feb 15 '16 at 11:48
  • 1
    There are some webs out there to check/validate regex. This one for example https://regex101.com/ – Pikoh Feb 15 '16 at 11:50

0 Answers0