Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help with Javascript Function (Case Sensitive)

Posted on 2012-04-04
4
Medium Priority
?
190 Views
Last Modified: 2012-04-21
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

////////////////////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"); 

} 

Open in new window


So if the user enters me@Yahoo.com, its not working.
Is it easy to modify the code to disregards casing?

Cheers in advance,
0
Comment
Question by:MimUK
[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
4 Comments
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 1200 total points
ID: 37805007
You may use toLowerCase in this case. For example,

x.toLowerCase().replace("@msn.", "").length < x.length
0
 
LVL 6

Expert Comment

by:ingriT
ID: 37805010
try this:

apos=x.indexOf("@"); 
dotpos=x.lastIndexOf("."); 
lastpos=x.length-1;

// INSERT THIS LINE
x = x.toLowerCase();

Open in new window


e-mail isn't case sensitive, so it shouldn't be an issue.
0
 
LVL 20

Expert Comment

by:Proculopsis
ID: 37805254


//Try this instead:

if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2 || x.match( /@(msn|gmail|hotmail|yahoo)\./i ) != null )
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 37812071
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

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

618 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