Validation question

S

Stu

I'm using the following validation code in an aspx form page, its the
standard email validation provided with MSVS 2003.

My question is how can I have validation triggered only if something has
been entered in the text box, i.e. email is not a required field, but if the
punter decides to let us have it I'd like it to be validated.

Bit new on C# and MSVS2003, so sorry if its a daft question.

Look forwarded to your replies.

Stu

<asp:regularexpressionvalidator id="RegularExpressionValidator1"
runat="server" ControlToValidate="txtEmail" ErrorMessage="Please enter a
valid email address"

ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:reg
ularexpressionvalidator>
 
H

Hans Kesting

Stu said:
I'm using the following validation code in an aspx form page, its the
standard email validation provided with MSVS 2003.

My question is how can I have validation triggered only if something has
been entered in the text box, i.e. email is not a required field, but if the
punter decides to let us have it I'd like it to be validated.

Bit new on C# and MSVS2003, so sorry if its a daft question.

Look forwarded to your replies.

Stu

<asp:regularexpressionvalidator id="RegularExpressionValidator1"
runat="server" ControlToValidate="txtEmail" ErrorMessage="Please enter a
valid email address"

ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:reg
ularexpressionvalidator>

That is the behavior you have now! All validators (except RequiredField)
ignore
"empty" fields (it seems that spaces are also ignored). So if you want a
required
field, you have to use the RequiredFieldValidator along with possible
others.

Hans Kesting
 
S

Stu

Thanks Hans

That will teach me to make assumptions and not test things properly before I
post !!!!

Stu




Hans Kesting said:
Stu said:
I'm using the following validation code in an aspx form page, its the
standard email validation provided with MSVS 2003.

My question is how can I have validation triggered only if something has
been entered in the text box, i.e. email is not a required field, but if the
punter decides to let us have it I'd like it to be validated.

Bit new on C# and MSVS2003, so sorry if its a daft question.

Look forwarded to your replies.

Stu

<asp:regularexpressionvalidator id="RegularExpressionValidator1"
runat="server" ControlToValidate="txtEmail" ErrorMessage="Please enter a
valid email address"
ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:reg
ularexpressionvalidator>

That is the behavior you have now! All validators (except RequiredField)
ignore
"empty" fields (it seems that spaces are also ignored). So if you want a
required
field, you have to use the RequiredFieldValidator along with possible
others.

Hans Kesting
 

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,776
Messages
2,569,602
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top