Uri

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I need to validate a URL contained on a String. I found a Regex
expression for this.

But could, and should, I validate the URL using System.Uri?

Maybe trying to create a URI and if any exception happens consider it
a false URL.

Does this make any sense?

Thanks,
Miguel
 
Note, my code idea was the following:

try
{
System.Uri test = new System.Uri(stringToTest);
}
catch (FormatException ex)
{
return false;
}
return true;
 
shapper said:
I need to validate a URL contained on a String. I found a Regex
expression for this.

But could, and should, I validate the URL using System.Uri?

Maybe trying to create a URI and if any exception happens consider it
a false URL.

I'd think it's cleaner to just use Uri.IsWellFormedUriString()
 
Back
Top