Validate an email address in ColdFusion using regular expressions (regexp)

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("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$", trim(myEmail))>
Valid email address
<cfelse>
Oops, email address does not validate
</cfif>
 

TweetBacks
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.5.002. Contact Blog Owner