1. Home
  2. Computing & Technology
  3. Visual Basic

Using Regular Expressions in ASP.NET

By , About.com Guide

2 of 7

Creating a URL Validation ASP.NET Application

The RegularExpressionValidator Propertie

The RegularExpressionValidator Properties

To demonstrate the basic idea, let's use a regex that's provided "in the box" with Visual Studio.NET: URL Validation. To create this app, select ASP.NET Web Application from the New Project menu in Visual Studio.NET. Add a TextBox and a RegularExpressionValidator. In the Properties of the RegularExpressionValidator, change the ControlToValidate to the name of the TextBox, and select Internet URL from the "Regular Expresson Editor" window that pops up when you click the three dots at the left side of the ValidationExpression property.

When you click the "run" icon, this simple application will automatically check whether anything entered into the Textbox is a valid URL,

The actual regex inserted into the property is:

http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?

If you haven't coded a regex before, something like this looks like "magic hieroglyphics" and can lead to banging your head against a wall. We'll create an easier one later and you can return to this one and see if it makes more sense to you then.

Explore Visual Basic
By Category
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Learn ASP.NET
  6. Using Regular Expressions in ASP.NET

©2010 About.com, a part of The New York Times Company.

All rights reserved.