CFLib.org – Common Function Library Project

getEmails(str)

Last updated June 13, 2011

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

 
Rated 11 time(s). Average Rating: 4.5

Description:
This UDF will search a string for email addresses and return the matches as a list.

Return Values:
Returns a list.

Example:

view plain print about
<cfset emailList = "Gerardo Trevi?o Rojas gtrevino@metro.com.mx,Guillermo Dewey <gdewey@metro.com.mx>,Ma Luisa <luisa@metro.com.mx>;sales'<info@kompressorserver.com>'">
<cfoutput>#getEmails(emailList)#</cfoutput>

Parameters:

Name Description Required
str String to search. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Searches a string for email addresses.
 * Based on the idea by Gerardo Rojas and the isEmail UDF by Jeff Guillaume.
 * New TLDs  
 * v3 fix by Jorge Asch
 * 
 * @param str      String to search. (Required)
 * @return Returns a list. 
 * @author Raymond Camden (ray@camdenfamily.com) 
 * @version 3, June 13, 2011 
 */

function getEmails(str) {
    var email = "(['_a-z0-9-]+(\.['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.((aero|coop|info|museum|name|jobs|travel)|([a-z]{2,3})))";
    var res = "";
    var marker = 1;
    var matches = "";
    
    matches = reFindNoCase(email,str,marker,marker);

    while(matches.len[1] gt 0) {
        res = listAppend(res,mid(str,matches.pos[1],matches.len[1]));
        marker = matches.pos[1] + matches.len[1];
        matches = reFindNoCase(email,str,marker,marker);        
    }
    return res;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Troy Pullis Troy Pullis added
firstXDayOfMonth
a while ago

Henry Ho Henry Ho added
arrayMap
a while ago

Henry Ho Henry Ho added
queryGetRow
a while ago

Tony Felice Tony Felice added
getRowFromQuery
a while ago

Top Rated

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

Barney Boisvert indentXml
Rated 5.0, 12 time(s)

Rachel Lehman deAccent
Rated 5.0, 9 time(s)

Markus Schneebeli                                 ListRemoveByStri...
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson