Solved

CFIF statement to validate email address

Posted on 2009-04-13
3
235 Views
Last Modified: 2012-05-06
Can someone help me write a CFIF statement to validate email address, I want to transfer email lists from other databases but i want to make sure all the emails that go into the new database are emails in the correct format. I use

validate="regular_expression"
pattern="[A-Za-z0-9_]+@[A-Za-z0-9_]+\.[A-Za-z]+"

for my form but i need to know how to use this in a CFIF tag??
0
Comment
Question by:overcolor
  • 2
3 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24131646
try this
<cfinput type="text" name="email" message="Email address is impoperly formatted." validate="regular_expression" pattern="^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$">
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 24131682
>  how to use this in a CFIF tag??

Try the IsValid(..) function:
http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_in-k_37.html

<cfif IsValid("email", form.yourFieldName)>
it is valid
<cfelse>
 not valid
</cfif>

> I use  ... for my form

You could also just use <cfinput validate="email" ..>
0
 
LVL 52

Expert Comment

by:_agx_
ID: 24131710
erikTsomik wrote:
> try this <cfinput type="text" name="email" ....>

Personally, I would use validate="email" for the client side validation.  It is a lot simpler.  Though you could also use that expression on the server side. See the IsEmail function at cflib.org, for an updated version of that expression:

http://www.cflib.org/index.cfm?event=page.udfbyid&udfid=216
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question