Regular expression for validating date in asp net

Introduction This article is about a Windows application and presents a more involved example that uses Regular Expressions to validate name, address and telephone number information input by a user.Before explaining the sample I would like to provide a little explanation of Regular Expressions.For example, a ZIP code must consist of five digits, and a last name must start with a capital letter.Compilers use Regular Expressions to validate the syntax of programs.I wrote my own regexp for the expiration date since one was not easily found on the net.This one validates for allowing the year 2009 to 2029, but could be easily changed…I built this for an ASP. This version just checks for 4 digits after the “/” character. It validates a numeric 2 digit month, allowing only for 01-12.

Now you can ask questions directly to me on my new site ASPForums.

The code above calls the first Name Text Box's Focus method to place the cursor in the first Name Text Box..

If there are no empty fields then the following code validates the first name by calling the static method Match of the Regex class, passing both the string to validate and the Regular Expression as arguments. This object contains a Success property that indicates whether a method Match's first argument matches the pattern specified by the Regular Expression in the second argument.

) and there are surly to many valid symbols to inlcude them all (and you will have Chinese symbols problem again).

I would not put any constraints on a user name - it may even contain numbers; think of aristocratic names. No matter what regex you come up with, I can find a name somewhere in the world that will break it.


Leave a Reply