Friday, May 4, 2012

ASP.NET - Set min and max number of characters using Regular Expression

We can set the min and max number of characters for input fields using Regular Expression (Regex for short). For example I use it with RegularExpressionValidator in ASP.NET MultiLine TextBoxes (which from some reason don't cooperate with nested MaxLength control property).
In this example I want to sent min as 8 and max as 16 characters, alphanumeric only (to add additional special characters type them between the "9" and the "\s"):

ValidationExpression=" ^[a-zA-Z0-9\s]{8,16}$ "


No comments:

Post a Comment