Alpha Regex validation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm trying to validate a textbox such that it only alpha
characters are accepted. I have the following Regex expression
[^a-zA-Z] exactly as shown in the RegularExpressionValidator control,
but it does not work.

Can someone help me out with this.

Thank You
 
You have reversed the expression [^] in the class means you do not want
these characters. Remove ^
 
Maybe useful to note there's a shorthand if you want to match
alphanumeric characters: "[a-zA-Z_0-9]" is equivalent to "\w" (word
characters).
 
Yes, but he doesn't want numeric characters.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
Thanks for you reply.

I've tried setting the ValidationExpression to [a-zA-Z]
of the regular expression validator control, but it is still fails
when inputting letters only in the text box i am validating.

Any ideas?
 
Hi Opa,

The pattern [a-zA-Z] will only match a single character, to match a
character string of any length, try: "[a-zA-Z]+".

Hope this helps,

Chris
 
Well, to be a bit more accurate, the '+' quantifier will not work with 0
characters. For a character string of *any* length (including 0), you would
use the '*' quantifier.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
Hi Opa,

Be careful using the "+" and "*" quantifiers to validate strings with
the RegularExpressionValidator. Although "[a-zA-Z]+" means an alpha
string with at least once character, it won't fail when the input
string is empty. This is because, by default, the
RegularExpressionValidator won't fire when there's an empty input. If
you want to disallow an empty string, use the RequiredFieldValidator
control as well.

HTH,

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top