problems with the regular expression validator on the client

C

Chris Barrow

Hi Everyone,

I am using a regular expression validator control in a web
form. I essentially want the control to pattern match
whether or not a user has enter non-digit characters into
a text field. Here is the control syntax along with the
reg expression:

<asp:regularexpressionvalidator id="rxvCity"
runat="server" controltovalidate="txtCity" display="None"
validationexpression="[^0-9]" errormessage="City field
cannot contain numeric characters"/>

Problem: the expression doesn't seem to validate. No
matter what I type into the text field, the errormessage
is always returned. Is there something wrong here with my
syntax for the reg expression? I have also tried "\D" but
that doesn't seem to work either. Curiously, another reg
validator control that uses the expression: "\d{3}-\d{3}-\d
{4}" works just fine.

If anyone has an idea on why this is happening, I would
greatly appreciate it.

Thanks,

Chris...
 
A

Axel Dahmen

Hi, Chris,

your expression expects *one single* character as input to validate is as
true. Add the "+" sign in order to validate "one or more" none digit values:
"[^0-9]+"

HTH,
Axel Dahmen
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top