RegularExpressionValidator?

D

DC

I have this snippet:

<tr>
<td align="left">E-mail</td>
<td>
<asp:TextBox id="txtEmail" runat="server"
MaxLength="100"></asp:TextBox>&nbsp;
<asp:RegularExpressionValidator id="revEmail" runat="server"
ErrorMessage="Enter a valid e-mail address"
ControlToValidate="txtEmail"

ValidationExpression="\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z0-9._%-]{2,4}\b">
</asp:RegularExpressionValidator>
</td>
</tr>

My question is why this regular expression is not invoked if I leave the
textbox blank?
My understanding is blank entry is not met the requirement of that regular
expression.

Am I missing something here?

- DC
 
C

Craig Deelsnyder

DC said:
I have this snippet:

<tr>
<td align="left">E-mail</td>
<td>
<asp:TextBox id="txtEmail" runat="server"
MaxLength="100"></asp:TextBox>&nbsp;
<asp:RegularExpressionValidator id="revEmail" runat="server"
ErrorMessage="Enter a valid e-mail address"
ControlToValidate="txtEmail"

ValidationExpression="\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z0-9._%-]{2,4}\b">
</asp:RegularExpressionValidator>
</td>
</tr>

My question is why this regular expression is not invoked if I leave the
textbox blank?
My understanding is blank entry is not met the requirement of that regular
expression.

Am I missing something here?

- DC

Validators normally aren't enabled when something is left blank. Why
that decision was made (especially for regex validators) I'll never
know. Slap a RequiredFieldValidator on the field as well and all shall
function properly (if not with a little extra maintenance on your part).
 
E

Earl Teigrob

I personally like the way Nicrosoft did that because you get two seperate
messages, one for [Required] and one for [Invalid].

Craig Deelsnyder said:
DC said:
I have this snippet:

<tr>
<td align="left">E-mail</td>
<td>
<asp:TextBox id="txtEmail" runat="server"
MaxLength="100"></asp:TextBox>&nbsp;
<asp:RegularExpressionValidator id="revEmail" runat="server"
ErrorMessage="Enter a valid e-mail address"
ControlToValidate="txtEmail"

ValidationExpression="\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z0-9._%-]{2,4}\b">
</asp:RegularExpressionValidator>
</td>
</tr>

My question is why this regular expression is not invoked if I leave the
textbox blank?
My understanding is blank entry is not met the requirement of that regular
expression.

Am I missing something here?

- DC

Validators normally aren't enabled when something is left blank. Why
that decision was made (especially for regex validators) I'll never
know. Slap a RequiredFieldValidator on the field as well and all shall
function properly (if not with a little extra maintenance on your part).
 
S

Scott M.

It makes perfect sense to me, IF you enter a value, it will be validated.
It's not a RequiredRegularExpressionValidator after all, it's just a
RegularExpressionValidator.


Craig Deelsnyder said:
DC said:
I have this snippet:

<tr>
<td align="left">E-mail</td>
<td>
<asp:TextBox id="txtEmail" runat="server"
MaxLength="100"></asp:TextBox>&nbsp;
<asp:RegularExpressionValidator id="revEmail" runat="server"
ErrorMessage="Enter a valid e-mail address"
ControlToValidate="txtEmail"

ValidationExpression="\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z0-9._%-]{2,4}\b">
</asp:RegularExpressionValidator>
</td>
</tr>

My question is why this regular expression is not invoked if I leave the
textbox blank?
My understanding is blank entry is not met the requirement of that regular
expression.

Am I missing something here?

- DC

Validators normally aren't enabled when something is left blank. Why
that decision was made (especially for regex validators) I'll never
know. Slap a RequiredFieldValidator on the field as well and all shall
function properly (if not with a little extra maintenance on your part).
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top