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

Using Regular Expressions in ASP.NET

By Dan Mabbutt, About.com

1 of 7

The Intersection of Regular Expressions and ASP.NET

RegEx Server and Client Validation

The Complete RegEx Server and Client Validation

About Visual Basic has featured articles introducing validation techniques for ASP.NET - "ASP.NET - Learn Programming for the Networked World - Part 2" and articles about how to use Regular Expressions - Introduction to Regular Expressions in Visual Basic. But there has not been an article at the site that talked about the two together. And that's a real miss because the RegularExpressionValidator control for ASP.NET is a powerful combination. (Note ... I will use the shorthand "regex" to mean "regular expression" in the remainder of this article.)

The other ASP.NET validation controls let you check for required values, comparisons and ranges, and even provide the ability to code any validation that you like in a custom event handler called by ASP.NET. But since validation is really checking text, and regexes are the premier way to check text, the RegularExpressionValidator control is just a natural fit!

The basic idea behind using the RegularExpressionValidator control is to add the control to a web form that also contains the control to be validated. Add the ID of the control to be validated and the actual regex code to the ValidationExpression property of the RegularExpressionValidator control ... and you're good to go! This does "Server Side" validation. You can also validate with client script and I'll show you a simple example after we get the initial application working.

1 of 7

Explore Visual Basic

More from About.com

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

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

All rights reserved.