Alpha Regex validation

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
 
W

Winista

You have reversed the expression [^] in the class means you do not want
these characters. Remove ^
 
C

Chris Fulstow

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).
 
K

Kevin Spencer

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.
 
G

Guest

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?
 
C

Chris Fulstow

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
 
K

Kevin Spencer

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.
 
C

Chris Fulstow

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

Similar Threads

RegEx 0
Entry validation 2
Regular Expression Help 2
My regex kung-fu is not strong =( 0
Regex pattern question 1
email validation 1
Check forms With JavaScript 1
Regex Question 2

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top