IsEmail Custom Tag

Download IsEmail.zip (4K)

Description

Requires ColdFusion 5 or greater.

IsEmail.cfm is a ColdFusion custom tag that validates email address formats according to RFC 3696.

Returns boolean value "IsEmail" indicating validation result and a string value "IsEmail_Err" with details if the validation fails. "IsEmail_Err" is empty if validation is successful.

Use this as the server-side component for email validation when using the JS Toolbox for client-side validation.

Syntax

<CF_IsEmail EMAILADDRESS="email address" MODE="full or common">

Attributes

EMAILADDRESS     (REQUIRED, string)     Email address to validate.
MODE     (OPTIONAL, string)     Local-part (ie, left of the @ sign) validation mode. "Full" (default) validates strictly according to RFC 3696. "Common" only allows common characters (alphanumerics, periods, hyphens and underscores).
RETVAR     (OPTIONAL, string)     Variable name to use for return value. Default is "IsEmail". Error message variable name will be this value with "_Err" appended to the end.

Examples

Email address format is valid

<CFPARAM NAME="Form.Email" DEFAULT="bugs@acme.com">
<CFPARAM NAME="Form.Mode" DEFAULT="">

<FORM ACTION="CFCTisemail.cfm" METHOD="post" NAME="TheForm">
<INPUT TYPE="text" NAME="Email" VALUE="<CFOUTPUT>#Form.Email#</CFOUTPUT>" SIZE="60">
<INPUT TYPE="checkbox" NAME="Mode" VALUE="Common"<CFIF Form.Mode IS "Common"> CHECKED</CFIF>>Common mode
<INPUT TYPE="submit" VALUE="Validate">
</FORM>

<CF_IsEmail EmailAddress="#Form.Email#" Mode="#Form.Mode#">

<CFIF IsEmail>
	<P>Email address format is valid
<CFELSE>
	<P>Email address format is NOT valid
	
	<P>Reason: <CFOUTPUT>#IsEmail_Err#</CFOUTPUT>
</CFIF>

Site last updated: 11 March 2012