CFLib.org – Common Function Library Project

isEmail(str)

Last updated May 8, 2009

Version: 7 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 15 time(s). Average Rating: 4.3

Description:
Tests passed value to see if it is a valid e-mail address (supports subdomain nesting and new top-level domains).

Return Values:
Returns a boolean.

Example:

view plain print about
<cfoutput>
#YesNoFormat(IsEmail("jguillaume@stoneage.com"))#<br>
#YesNoFormat(IsEmail("jguillaume@stoneage.com.info"))#<br>
#YesNoFormat(IsEmail("jguillaume@subdomain.stoneage.museum"))#<br>
#YesNoFormat(IsEmail("jguillaume@stoneage.invalidTLD"))#
</cfoutput>

Parameters:

Name Description Required
str The string to check. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Tests passed value to see if it is a valid e-mail address (supports subdomain nesting and new top-level domains).
 * Update by David Kearns to support '
 * SBrown@xacting.com pointing out regex still wasn't accepting ' correctly.
 * Should support + gmail style addresses now.
 * More TLDs
 * Version 4 by P Farrel, supports limits on u/h
 * Added mobi
 * v6 more tlds
 * 
 * @param str      The string to check. (Required)
 * @return Returns a boolean. 
 * @author Jeff Guillaume (SBrown@xacting.comjeff@kazoomis.com) 
 * @version 7, May 8, 2009 
 */

function isEmail(str) {
    return (REFindNoCase("^['_a-z0-9-\+]+(\.['_a-z0-9-\+]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|asia|biz|cat|coop|info|museum|name|jobs|post|pro|tel|travel|mobi))$",
arguments.str) AND len(listGetAt(arguments.str, 1, "@")) LTE 64 AND
len(listGetAt(arguments.str, 2, "@")) LTE 255) IS 1;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
3 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson