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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Address Validation: Non-CFFORM

Status
Not open for further replies.

felixtkatt

Programmer
May 14, 2001
18
US
I'm attempting to create a (very) weak email validation bit using a simple CFIF and a few string functions. Here's the code:

Code:
<cfif (FindNoCase(emailFrom, &quot;.com&quot;) IS NOT 0) OR 
      (FindNoCase(emailFrom, &quot;.net&quot;) IS NOT 0) OR
      (FindNoCase(emailFrom, &quot;.org&quot;) IS NOT 0) OR
      (FindNoCase(emailFrom, &quot;.edu&quot;) IS NOT 0) OR
      (FindNoCase(emailFrom, &quot;.gov&quot;) IS NOT 0)>

...Do good email stuff...
<cfelse>
...Tell them their dumb for typing a bogus email address...
</cfif>

emailFrom contains the email address from a form field on the previous page. The real sticker is that FindNoCase is returning 0 on every call. I tried having the function search for the &quot;at&quot; symbol (@) instead, and it still came up 0. Are there characters that FindNoCase can't find? Is my sytax wrong somewhere? Someone please help! FTK
 

A regular expresison would do the best. Keep in mind, there's all sorts of email addresses now, especially condidering email address from different countries. There are a lot of emails out there that do not have the domain extensions listed above.

<CFIF REFindNoCase(&quot;^
Code:
[
^@%*<>
Code:
]
+@
Code:
[
^@%*<>
Code:
]
{2,255}\.
Code:
[
^@%*<>
Code:
]
{2,5}&quot;
, trim(form.emailFrom)) IS 0>

<CFSET ErrorMessage = ErrorMessage & &quot;<LI>Sorry, you have entered an invalid E-mail address.<BR>&quot;>
</CFIF>

Translated into english, the email address may be in the following format:
address name, at least one character, may not contain the following characters, right after the start of the line (&quot;@%*<> &quot;). Then an @ symbol (&quot;@&quot;) then the domain name that may not contain the above characters, again, of a minimum length of 2, maximum 255. Then a period (&quot;\.&quot;), then a series of characters (the top level domain) that may not contain the above, again.

It is important to trim the e-mail to take off blank space.


If you wanted to just check for the common domains you listed, you could to.

<CFIF REFindNoCase(&quot;^
Code:
[
^@%*<>
Code:
]
+@
Code:
[
^@%*<>
Code:
]
{2,255}\.(com|net|org|edu|gov)&quot;
, trim(form.emailFrom)) IS 0>

<CFSET ErrorMessage = ErrorMessage & &quot;<LI>Sorry, you have entered an invalid E-mail address.<BR>&quot;>
</CFIF> - tleish
 
I guess I should learn regular expressions, huh? :p

Thanks for your help, that CFIF was exactly what I needed. FTK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top