Reply
Tip - How to validate a URL
Old 07-02-2007, 06:05 PM Tip - How to validate a URL
Learning Newbie's Avatar
Moderator

Latest Blog Post:
Dick Cheney as a Web Comic
Posts: 4,622
Name: John Alexander
It's easy - you don't need regular expressions at all! Just construct a URI with a string seed value, and if it doesn't throw an exception, you're golden! That doesn't tell you whether the resource actually exists on the server, only whether the string is a valid URL.

Code:
try {
   Uri urlTest = new Uri("http://www.example.com");
   // Do your thing!
} catch(Exception ex) {
   System.Diagnostics.Debug.WriteLine("Not a valid url!");
}
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 07-09-2007, 02:15 PM Re: Tip - How to validate a URL
Experienced Talker

Posts: 32
Name: Arnold Smith
thanks ... good share
arnold is offline
Reply With Quote
View Public Profile Visit arnold's homepage!
 
Reply     « Reply to Tip - How to validate a URL
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13855 seconds with 13 queries