Email Address Validation

Posted on 2011-10-26
Last Modified: 2012-05-12
I need to amend a function that will prevent users from entering an @gmail or @msn or @yahoo email address to a web based CRM application

The code attached works fine and warns if the format of the address is not correct.

However, based on this script, could someone help with changes required to prevent the above from happening.

Many thanks
function emailvalidation(x,y) 
if (x.length>0) 
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
Valid = false; 
ErrorStr = CRM.GetTrans("colnames",y)+ " ["+x+"] "+ CRM.GetTrans("GenCaptions","BadMailAddress"); 

Open in new window

Question by:MimUK
    LVL 25

    Accepted Solution

    In principle quite simple but when you get into it, quite difficult. Id do this...


    if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2)


    if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2 || x.replace("@gmail.", "").length < x.length || x.replace("@yahoo.", "").length < x.length || x.replace("@msn.", "").length < x.length || x.replace("@googlemail.", "").length < x.length)

    I added as it is synonymous with

    LVL 25

    Expert Comment

    by:Lee Savidge
    You could if you wanted to get clever with it, add all these restricted domains as translations in CRM and that way you could rewrite the function so that the function loops around checking whatever the end customer has added to translations so the list could be modified without altering the script.

    Depends how clever you wanted to be with it.


    Author Closing Comment

    Great Thanks.
    Works a Treat

    Author Comment

    Having deployed the script...

    We have found that if the user enters @MSN or @Gmail the validation doesn't work as the expression is case sensitive.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now