Welcome to AspAdvice Sign in | Join | Help

URL Validation

This is a simple URL Validation Application written in C#  

 Click here for a complete article:

http://www.devtalklive.com/cmsnet/CDA/StoryPg.aspx?ID=13&Ver=2

using System;
namespace CSharpProj {
public class WebSite
{
const string http = @"http//";
const string httpwww = @"http://www.";
string siteName;
string url;
string description;
public WebSite(): this("No Site", "No url", "No Description"){}
public WebSite(string newSite): this(newSite, "No url", "No Description"){}
public WebSite(string newSite, string newURL): this(newSite, newURL,
"No Description"){}
public WebSite(string newSite, string newURL, string newDesc)
{
this.siteName = newSite;
this.url = newURL;
this.description = newDesc;
Console.WriteLine(this.siteName + " " + this.url + " " + this.description)
;
}
public string ValidateUrl(string url)
{
if ((url.StartsWith("www.")))
{
return "[Passed without,so adding http]--> " + http + url;
}
if (!(url.StartsWith(httpwww)))
{
return "[Passed without,so adding httpwww]--> " + httpwww + url;
}
return "[Passed with httpwww]--> " + url;
}
public string ValidateUrl(ref string url)
{
if ((url.StartsWith("www.")))
{
return url = http + url;
}
if (!(url.StartsWith(httpwww)))
{
return url = httpwww + url;
}
return url;
}
}
public class WebSiteTester
{
static void Main()
{
string url = "google.com";
WebSite web = new WebSite("Hotmail", "http://www.hotmail.com");
string myurl = web.ValidateUrl("http://www.yahoo.com");
Console.WriteLine(myurl);
Console.WriteLine("Before: " + url);
web.ValidateUrl(ref url);
Console.WriteLine("After: " + url);
DateTime dt = Convert.ToDateTime("8/1/2005");
Console.WriteLine(string.Format("{0:MMMM yyyy}", dt));
//would print August 2005
}
}
}

Published Monday, February 26, 2007 8:35 PM by Bilal_Khawaja

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below