Uri

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
 
S

shapper

Note, my code idea was the following:

try
{
System.Uri test = new System.Uri(stringToTest);
}
catch (FormatException ex)
{
return false;
}
return true;
 
S

Scott Seligman

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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top