MimUK
asked on
Help with Javascript Function (Case Sensitive)
I have some code that prevents emails being entered into a web based application with certain domains.
It works if the emails are entered as defined, however it is case sensitive and emails can be entered by capitalising any of the letters
So if the user enters me@Yahoo.com, its not working.
Is it easy to modify the code to disregards casing?
Cheers in advance,
It works if the emails are entered as defined, however it is case sensitive and emails can be entered by capitalising any of the letters
////////////////////Helper Functions Start///////////////////////
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 || x.replace("@msn.", "").length < x.length || x.replace("@gmail.", "").length < x.length || x.replace("@hotmail.", "").length < x.length || x.replace("@yahoo.", "").length < x.length)
{
Valid = false;
ErrorStr = CRM.GetTrans("colnames",y)+ " ["+x+"] "+ CRM.GetTrans("GenCaptions","BadEmailInternal");
}
}
}
/////////////////////Helper Functions End///////////////////////
function InsertRecord()
{
// Handle insert record actions here
emailvalidation(FormValues("emai_emailaddress"),"emai_emailaddress");
}
So if the user enters me@Yahoo.com, its not working.
Is it easy to modify the code to disregards casing?
Cheers in advance,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
//Try this instead:
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2 || x.match( /@(msn|gmail|hotmail|yahoo
Here the complete Helper function:
function emailvalidation(x,y) {
if (x.length>0){
if(!(x.replace(/\@(msn|gmail|hotmail|yahoo)\./mi,"").match(/^\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.[a-z]{2,4}$/i))){
Valid = false;
ErrorStr = CRM.GetTrans("colnames",y)+ " ["+x+"] "+ CRM.GetTrans("GenCaptions","BadEmailInternal");
}
}
}
Open in new window
e-mail isn't case sensitive, so it shouldn't be an issue.