RegularExpressionValidator allowing no entry

T

tshad

I have a RegularExpressionValidator that doesn't seem to work correctly if
you don't enter anything. In the following, it works correctly if you have
at least 1 character. If you just enter through the field it lets you (even
thoug no entry would be less that 6 characters.

<asp:textbox id="password1" TextMode="Password" Columns="45"
runat="server" /><asp:label text=" 6-20 characters with at least 1 numeric"
style="color:red" runat="server"/>
<asp:RegularExpressionValidator
ControlToValidate="password1"
Display="Dynamic"
Text="<br>Your password must contain between 6 and 20 characters!"
ValidationExpression="\w{6,20}"
Runat="Server" />

<asp:RegularExpressionValidator
ControlToValidate="password1"
Display="Dynamic"
Text="<br>Your password must contain at least one number and
letter!"
ValidationExpression="[a-zA-Z]+\w*\d+\w*"
Runat="Server" />

I can solve the problem by also putting a RequiredFieldValidator, it's just
that that requires another object that shouldn't be needed (at least, I
wouldn't think so).

Tom
 
K

Karl Seguin

Tshad:
That's how the regular expression validator works...so you need that extra
field...though I agree with you it shouldn't be like that....

Karl
 
T

tshad

Karl Seguin said:
Tshad:
That's how the regular expression validator works...so you need that extra
field...though I agree with you it shouldn't be like that....

I figured that was the case.

Bummer.

Thanks,

Tom
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


tshad said:
I have a RegularExpressionValidator that doesn't seem to work correctly
if
you don't enter anything. In the following, it works correctly if you have
at least 1 character. If you just enter through the field it lets you (even
thoug no entry would be less that 6 characters.

<asp:textbox id="password1" TextMode="Password" Columns="45"
runat="server" /><asp:label text=" 6-20 characters with at least 1 numeric"
style="color:red" runat="server"/>
<asp:RegularExpressionValidator
ControlToValidate="password1"
Display="Dynamic"
Text="<br>Your password must contain between 6 and 20 characters!"
ValidationExpression="\w{6,20}"
Runat="Server" />

<asp:RegularExpressionValidator
ControlToValidate="password1"
Display="Dynamic"
Text="<br>Your password must contain at least one number and
letter!"
ValidationExpression="[a-zA-Z]+\w*\d+\w*"
Runat="Server" />

I can solve the problem by also putting a RequiredFieldValidator, it's just
that that requires another object that shouldn't be needed (at least, I
wouldn't think so).

Tom
 
P

pj

I have a RegularExpressionValidator that doesn't seem to work correctly if
you don't enter anything. In the following, it works correctly if you have
at least 1 character. If you just enter through the field it lets you (even
thoug no entry would be less that 6 characters.

Pretty irritating isn't it? The RegularExpressionValidator only
attempts to validate the control if there is something there. Ugly.

pj
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top