Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 2-Jan-13 0:04am
AkshayV270
Comments
Tadit Dash at 2-Jan-13 5:09am
   
What type of content you are referring to?
Please be specific.
AkshayV at 7-Jan-13 1:48am
   
Only characters
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,580
1 OriginalGriff 8,370
2 Peter Leow 4,859
3 Kornfeld Eliyahu Peter 3,210
4 Maciej Los 2,301


Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100