Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate email address only when entered

Status
Not open for further replies.

DrumAt5280

Technical User
Sep 8, 2003
194
US
<CFINPUT TYPE="Text" NAME="contactEmail" required="no" "regular_expression" pattern="[A-Za-z0-9_]+@[A-Za-z0-9_]+\.[A-Za-z]+" message="Please enter a valid Email Address">

This code works fine when validating an entered email address, however when nothing is entered it pulls the error message which is strange since the required="no" is in the tag. Any ideas what i am doing wrong?
 
It may be testing the content, rather than for existence, as you have your regex set up. The field is not really empty. You do have an email address: ""

And of course it is not valid. I'm not sure how to account for a blank field with required = No.

Make required Yes, or drop the regex.....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top