Click here to Skip to main content
15,896,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I initiate a validator to check content in asp.net??I want a regular expression validator to to validate content on text change
Posted
Comments
What type of content you are referring to?
Please be specific.
AkshayV 7-Jan-13 1:48am    
Only characters

Hi,

Try the following,

Adding ASP.NET validation at runtime[^]

http://stackoverflow.com/questions/9297822/setting-regularexpressionvalidator-validationexpression-at-runtime[^]

If the above is not working, try the below

1. Add a using statement to reference the System.Text.RegularExpressions namespace.

2. Add the following code in your textchange event,

Regex reg = new Regex(@"^[a-zA-Z'.]{1,40}$");
Response.Write(reg.IsMatch(txtName.Text));

// Static method:
if (!Regex.IsMatch(txtName.Text, 
                   @"^[a-zA-Z'.]{1,40}$"))
{
  // Name does not match schema
}
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900