Link to home
Start Free TrialLog in
Avatar of MimUK
MimUK

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

Avatar of MimUK
MimUK

ASKER

Great Thanks.
Works a Treat
Avatar of MimUK

ASKER

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.