Validate an email address in ColdFusion

To validate an email address in ColdFusion, we use the regular expression shown below.

You could easily add this to a CFC if you wanted to return a true or false depending whether the email address validates or not.

<cfset myEmail = "test@test.com">
<CFIF REFindNoCase("^[^@%*<> ]+@[^@%*<> ]{2,255}\.[^@%*<> ]{2,5}", trim(myEmail))>
Valid email address
<cfelse>
Oops, email address does not validate
</cfif>
 

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner