?
Solved

Email Validation in a CFFORM

Posted on 2005-03-07
6
Medium Priority
?
315 Views
Last Modified: 2013-12-24
Can someone post a script for validatiing an email address in a CFFORM? Currently I have it required='yes' but I have no validation for the format. A user could enter joeblow@@domain...com and the form would be processed as normal. Does anyone have any code I could use?

Thanks,

IShiva
0
Comment
Question by:IShiva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:kyle1830
ID: 13477214
here is a js function that I use.
<script>
    function checkEmail(strEmail) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strEmail))
        {
            return (true);
        } else {
            return (false);
        }
    };
</script>

kyle
0
 

Author Comment

by:IShiva
ID: 13490473
Can you post some code to help me in placing that code on the page? Im not sure where is goes or how to get it to work. Thanks kyle

IShiva
0
 
LVL 8

Accepted Solution

by:
kyle1830 earned 200 total points
ID: 13490838
here is an example before the submit button is clicked:
<script>
    function checkEmail(strEmail) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strEmail))
        {
            return (true);
        } else {
                    alert ('Fix the email!!');
        }
    };
</script>
<form action="index.cfm" method="post">
      <input type="text" name="test" onblur="checkEmail(this.value);">
      <br>
      <input type="Submit" name="submit" value="submit">
</form>


then the same thing but when the button is clicked
<script>
    function checkEmail() {
       var a = document.testform.test.value
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(a))
        {
            return (true);
        } else {
                    alert ('Fix the email!!');
         return (false);
        }
    };
</script>
<form action="index.cfm" method="post" name="testform" onSubmit="return checkEmail();">
      <input type="text" name="test" value="">
      <br>
      <input type="Submit" name="submit" value="submit">
</form>

hope this helps
kyle


0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Expert Comment

by:tnunamak
ID: 13494237
Use this UDF from www.cflib.org

<cfscript>
/**
 * Tests passed value to see if it is a valid e-mail address (supports subdomain nesting and new top-level domains).
 * Update by David Kearns to support '
 * SBrown@xacting.com pointing out regex still wasn't accepting ' correctly.
 *
 * @param str        The string to check. (Required)
 * @return Returns a boolean.
 * @author Jeff Guillaume (jeff@kazoomis.com)
 * @version 2, August 15, 2002
 */
function IsEmail(str) {
        //supports new top level tlds
if (REFindNoCase("^['_a-z0-9-]+(\.['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$",str)) return TRUE;
      else return FALSE;
}
</cfscript>

0
 

Author Comment

by:IShiva
ID: 13495540
Thanks Kyle, worked like a charm!

sorry tnunamak, i didnt try yours since the previous post worked...but thanks for posting!!

ishiva
0
 
LVL 8

Expert Comment

by:kyle1830
ID: 13495636
you're welcome ishiva......good luck
0

Featured Post

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question