Last active
December 17, 2015 01:39
-
-
Save russplaysguitar/5530257 to your computer and use it in GitHub Desktop.
Select only records with valid e-mail addresses from a table using UnderscoreCF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
// setup QofQ | |
myQuery = QueryNew("Name, Email, Time, Advanced", "VarChar, VarChar, Time, Bit"); | |
QueryAddRow(myQuery, 2); | |
QuerySetCell(myQuery, "Name", "Rich", 1); | |
QuerySetCell(myQuery, "Email", "rich@rich.com", 1); | |
QuerySetCell(myQuery, "Time", "9:15 AM", 1); | |
QuerySetCell(myQuery, "Advanced", False, 1); | |
QuerySetCell(myQuery, "Name", "Bob", 2); | |
QuerySetCell(myQuery, "Email", "bob.rich.com", 2); | |
QuerySetCell(myQuery, "Time", "12:15 PM", 2); | |
QuerySetCell(myQuery, "Advanced", True, 2); | |
writeDump(var=myQuery, label="Original record set"); | |
// instantiate Underscore library | |
_ = new Underscore(); | |
// get an array of structs representing the records with valid email addresses | |
result = _.filter(myQuery, function (record) { | |
return isValid('email', record.email); | |
}); | |
writedump(var=result, label="Records with valid e-mail addresses."); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment