Recent Articles

Visual Studio 2005 - Publishing Web Site
What's the purpose of site precompilation? As it turns out, improved performance is often brought as an...

Microsoft Bridging VB6 And .NET Forms
A new toolkit from Microsoft will allow VisualBasic 6 developers to craft .Net WinForms that can be displayed in a VB6 application.

ASP.NET: How To Create Custom Trace Messages
This article is an excerpt from the book: Murach's ASP.NET 2.0 Web Programming with C# 2005. The Trace feature is an ASP.NET feature that displays some...

How To Use Breakpoints
This article is an excerpt from the book: Murach's ASP.NET 2.0 Web Programming with C# 2005. Figure 4-9 shows how to use breakpoints in an ASP.NET application.

How To Use The Exception Assistant
This article is an excerpt from the book: Murach's ASP.NET 2.0 Web Programming with C# 2005. Figure 4-9 shows how to use breakpoints in an ASP.NET application.

ASP.NET: Testing a file-system web site with IIS
This article is an excerpt from the book: Murach's ASP.NET 2.0 Web Programming with C# 2005. When you run a...

ASP.NET School For The Online Mind
A New Jersey firm now offers three online courses in ASP.NET programming, delivered through a browser. TeachMeIT recently added Programming with Microsoft...


10.27.06


Validating A URL With Regular Expressions

By Mads Kristensen

I had to build web form that took user input from standard ASP.NET input controls. In one of the text boxes the user must enter a valid URL, so I had to make some validation logic.

But first of all, I had to find out what kind of URL's we would accept as being valid. These are the rules we decided upon:

• The protocol must be http or https

• Sub domains are allowed

• Query strings are allowed

Based on those rules, I wrote this regular expression:


It is used in a RegularExpressionValidator control on the web form and on a business object in C#.



Low Rate eCommerce & Retail Plans

Here is the server-side validator method used by the business object:


You can add more protocols to the expression easily. Just add them to the beginning of the regular expression:


You can also allow every thinkable protocol containing at least 3 characters by doing this:




About the Author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

About WebProASP
WebProASP is a collection of up to date tutorials and insightful articles designed to help ASP users of any skill level implement successful ASP systems and practices. ASP Strategies and Tactics for Business

WebProASP is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQlProNews.com
ITcertificationNews.com SysAdminNews.com
WebProASP.com WirelessProNews.com
CProgrammingTrends.com ITManagementNews.com




-- WebProAsp is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2006 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article



ASP Strategies and Tactics for Business WebProASP News Archives About Us Feedback WebProASP Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact