Solved

CFIF statement to validate email address

Posted on 2009-04-13
3
240 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Having an issue with NumberFormat 7 62
need help with one more  outer join sql query in coldfusion 4 61
ColdFusion 10 Error 2 76
Cold Fusion form reset button issues. 11 30
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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