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!

Email Validation 1

Status
Not open for further replies.

hc1619

Programmer
Feb 17, 2004
62
NZ
I'm wanting to do some thorough validation on the email address people use to sign up with on my site.

I'm not using cfinput (and dont want to).. so I need a solid RE script to do this for me.

At the moment all I'm using is this: ReFind(".+@.+..+", form.emailAddress).

But i'd like to use something that disallows people from entering in illegal characters.. something that will check all syntax and characters.

Anyone know of anything I can use?

thanks.
 
I use a custom tag called CF_EmailVerify. It works pretty well, you can get it here from the Macromedia Exchange.

Here's another one that I found that you may be interested in. CF_IsEmail




Hope This Helps!

Ecobb

"My work is a game, a very serious game." - M.C. Escher
 
In terms of Regular expressions we use this from time to time:

<CFSET email_re = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$">

which seems to work quite well.

But when we want to know for sure if the email exists we use the email verifier from cfdev
Hope this helps!

Tony
 
This is the custom tag I use. It doesn't verify TLDs or anything, but it checks for proper structure.

Code:
<cfset email = attributes.email>
 
<CFSET AtsignPos = 0>
<CFSET PeriodPos = 0>
<CFSET SpacePos = 0>
<CFSET Length = Len(Email)>
<CFLOOP INDEX = "LoopCount" FROM = "1" TO = "#Length#">
 <CFSET Pos = LoopCount>
 <CFSET SingleChar = Mid(Email, Pos, 1)>
 <CFIF SingleChar IS Chr(64)>
  <CFSET AtsignPos = Pos>
 <CFELSEIF SingleChar IS Chr(46)>
  <CFSET PeriodPos = Pos>
 <CFELSEIF SingleChar IS Chr(32)>
  <CFSET SpacePos = Pos>
 </CFIF>
</CFLOOP>

<cfif spacepos is not 0>
 <cfset verifyemailaddr = 0>
<cfelseif atsignpos GT periodpos>
 <cfset verifyemailaddr = 0>
<cfelseif (length - periodpos) LT 2>
 <cfset verifyemailaddr = 0>
<cfelseif (periodpos - atsignpos) LTE 2>
 <cfset verifyemailaddr = 0>
<cfelseif atsignpos LT 3>
 <cfset verifyemailaddr = 0>
<CFELSE>
 <CFSET VerifyEmailAddr = -1>
</CFIF>

<cfif verifyemailaddr is 0>
 <cfset caller.emailok = "no">
<cfelse>
 <cfset caller.emailok = "yes">
</cfif>

Just save it as checkemail.cfm and use it like this:
Code:
<cf_checkemail email="#form.custemail#">
<cfif emailok is "yes">
 ...
<cfelse>
 ...
</cfif>
 
If you're serious about it, I'd suggest you go with arperry's.. It looks pretty good..

For the record, this is what I used for a while.. It was pretty basic but eh..

Code:
<cfif listlen(email,"@" eq 2 and listlen(listlast(email,"@"),".") gt 1 and len(trim(email)) gte 6>...</cfif>

I generally tossed in a mild regex to filter out slashes and such.. but I use that on sites where I'm not very serious about what the user entered..

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Code:
<cfif listlen(email,"@"[b])[/b] eq 2 and listlen(listlast(email,"@"),".") gt 1 and len(trim(email)) gte 6>...</cfif>

Oh, for the ability to edit posts...

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
This works really well for me in a similar situation.

<cfif REFindNoCase("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$", #form.email#) neq 1 >
Please enter a valid email address.<br>
<a href="javascript:window.close()">Close Window</a>
</cfif>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top