Nov 08
15
Two Useful Form Field Validation Functions
Here are two quick ColdFusion scripts to validate if a user supplied a real e-mail address or website URL using Regular Expressions.
To validate an e-mail address:
<cfif REFindNoCase("^[\w\.-]+@[\w\.-]+\.[a-zA-Z]{2,3}$",form.EMAIL) lt 1>
<--- E-mail address was not valid.... --->
</cfif>
... and to validate a website url:
<cfif REFindNoCase("^(http://|https://)[\w\.-]+\.[a-zA-Z]{2,3}(/?)$",form.WEBSITE) lt 1>
<--- Website URL was not valid.... --->
</cfif>
I wanted to post these real quick just so I have them handy, but also you might find them useful as well.
Have something to say? Leave a comment!
You don't have to be registered to leave a comment. Unregistered user's comments will be approved before going live.
You are currently posting as an unregistered user.
This means that your comment will be reviewed prior to going live. If you are a registered user, please login. New user? No problem, register for an account, it's FREE! Benefits include, posting instantly, screen name protection, collaboration recognition, subscribe to article updates, and so much more!