Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Regular Expression Validation Help


Message #1 by "Sion Edwards" <sion@h...> on Mon, 29 Apr 2002 12:19:22
Hi,

I am having problems with Regular Expression Validation. Can anyone 
suggest one for the following rules:

The textbox must contain 1 or 2 letters followed by 1 or 2 numbers

Thanks

Sion Edwards
Message #2 by "Andrew Polshaw" <andrewp@w...> on Mon, 29 Apr 2002 15:15:03
Assuming that you don't mind only accepting ASCII characters (it gets very 
scary otherwise), it would look like this:

^[A-Z]{1,2}\d{1,2}$

You need the ^ and $ to match the beginning and end of the text box, 
otherwise you can have any number of letters and any number of numbers.

Oh, one more thing, I presume you want it to be case-insensitive, so add 
RegexOptions.IgnoreCase as next parameter on the constructor (e.g.

matcher = new Regex("^[A-Z]{1,2}\d{1,2}$", RegexOptions.IgnoreCase)
matcher.IsMatch(string)


> Hi,

> I am having problems with Regular Expression Validation. Can anyone 
s> uggest one for the following rules:

> The textbox must contain 1 or 2 letters followed by 1 or 2 numbers

> Thanks

> Sion Edwards

  Return to Index