Jon Austin wrote:
> Does anyone know of a function to validate email addresses that
> matches the accepted address formats for CFMAIL?
this should pick up the bits in MX's javamail. the javamail parser takes
a pretty practical approach to this, at least according to the javadocs,
so it should work much of the time. as it's running on top of what MX
actually uses, i prefer this approach to a bunch of regex goop.
<cfscript>
function verifyEmail(testAddr,strictParse,parseAddr) {
// testAddr=single email address to test (string)
// strictParse=parse sort of strict to RFC822 syntax rules (boolean)
// parseAddr=parse testAddr to component parts (boolean)
var inetAddr=createObject("java","javax.mail.internet.InternetAddress");
var errMsg=structNew();
var parsedAddr="";
var e="";
errMsg.isOK=true;
try {
parsedAddr=inetAddr.parse(arguments.testAddr,arguments.strictParse);
}
catch (javax.mail.internet.AddressException e) {
errMsg.msg=e.message;
errMsg.type=e.type;
errMsg.reference=e.ref;
errMsg.isOK=false;
}
if (arguments.parseAddr AND errMsg.isOK) {
errMsg.emailAddress=parsedAddr[1].getAddress(); //parse returns
array
of addresses
errMsg.personal=parsedAddr[1].getPersonal();
}
return errMsg;
}
testAddr='[EMAIL PROTECTED] (Rob Smith)';
test=verifyEmail(testAddr,true,true);
</cfscript>
<cfdump var="#test#">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net
http://www.cfhosting.net
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:185414
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54