Email Address Validation

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) 
{ 
apos=x.indexOf("@"); 
dotpos=x.lastIndexOf("."); 
lastpos=x.length-1; 
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

MimUKAsked:
Who is Participating?
 
Lee SavidgeCommented:
In principle quite simple but when you get into it, quite difficult. Id do this...

Replace:

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

With:

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 googlemail.com as it is synonymous with gmail.com.

0
 
Lee SavidgeCommented:
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.

0
 
MimUKAuthor Commented:
Great Thanks.
Works a Treat
0
 
MimUKAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.