A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
How to validate an URL using RegEx in C#
On Saturday, October 22nd 2005 at 04:50 AM
By Andrew Pociu (View Profile)
(Rated 2.5 with 8 votes)
The magic here is in the Regex string. This validation method works great, with one minor exception: it will also mark URLs that don't start with http:// as valid. This means that both www.geekpedia.com and http://www.geekpedia.com will be marked as valid. However, most of the time in your application you will want the URL to contain http://. The best solution to this is not to throw an error to the user telling the URL is invalid, because that might confuse him. The best solution is to check if the URL starts with http:// and add it to the beginning of the string accordingly. We don't need RegEx this time, the IsPrefix() method will do. So here's the complete code to validate an URL:
What we're doing here: before validating the string against the RegEx expression, we check to see if it starts with http:// (using IsPrefix()), and if it doesn't, we add it to the beginning of the string.
|Digg It! Del.icio.us Reddit StumbleIt Newsvine Furl BlinkList|
Rate this Knowledge Base article
Related Knowledge Base Articles
There are no related KB articles.
Related Source Code
There is no related code.
There are no related tutorials.
C# Job Search