0

I have the following Regex

"^http\\\\://[a-zA-Z0-9\\\\-\\\\.]+\\\\.[a-zA-Z]{2,3}(/\\\\S*)?$";

But I'm not sure that it's validating URLs correctly. Is anyone able to assist me or see what's wrong with this?

Thanks

Dagg Nabbit
  • 72,560
  • 18
  • 107
  • 141
Tom
  • 1
  • 1

3 Answers3

2

If you want a solid pattern read here.

Looks like Rakesh some good mods to your existing pattern; however, if I were you I would consider the aforementioned patterns because they are a bit more robust depending on your scenario.

Community
  • 1
  • 1
Mike Veigel
  • 3,798
  • 2
  • 18
  • 28
1

Try this, there a quite a bit of escapes "/" in your version

var subUrlSTR = "http://subdomain.stackoverflow.com";
var urlSTR = "http://stackoverflow.com";
var result = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
console.log(subUrlSTR.match(result));
console.log(urlSTR.match(result));

See it working here

Rakesh Sankar
  • 9,187
  • 4
  • 40
  • 66
  • thanks a lot :) I do only want to match http://*.example.com where * can be any valid ? So i.e. http://www.example.com or http://blog.example.com ? – Tom Jun 20 '11 at 05:01
0
if (Uri.TryCreate(stringUrl, UriKind.Absolute, out uri))
{
    ...
}
Yuriy Faktorovich
  • 64,850
  • 14
  • 101
  • 138