SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot themissingelf's Avatar
    Join Date
    Nov 2001
    Location
    UK
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript toLowerCase for comparing email addresses

    I'm using the following script to compare two email addresses to make sure that they are the same. I want to ignore differences that are simply down to the visitor using capital letters in one field and lowercase in the second. I'm guessing the 'toLowerCase' (or 'toUpperCase') before the comparison is the way to do this, however, I've not been successful in getting this to work.

    Can anyone advise where to incorporate the case change in the script?

    PHP Code:
    function emailCheck(enquiryForm) {
    if (
    enquiryForm._008_email2.value != enquiryForm._008_email.value) {
    alert("The e-mail addresses that you entered do not match. Please amend. Thank you");
    enquiryForm._008_email.focus(); return false;}

    Thanks

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2001
    Location
    Tucson, Arizona
    Posts
    1,858
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simple enough.
    Code:
    function emailCheck() {
    	if (enquiryForm._008_email2.value.toLowerCase() != enquiryForm._008_email.value.toLowerCase()) {
    		alert("The e-mail addresses that you entered do not match. Please amend. Thank you.");
    		enquiryForm._008_email.focus(); 
    		return false;
    	}
    	return true;
    }

  3. #3
    SitePoint Zealot themissingelf's Avatar
    Join Date
    Nov 2001
    Location
    UK
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried this, however, the script continued to detect the difference between "D" and "d" (which is what I am using to test).

    Any idea where else the flaw may lie?

    Thanks

    Elf

  4. #4
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I never understood the reason for using a form that asks for the user's email address twice - I ALWAYS copy and paste it from the first field to the second one, as I imagine most people would. Asking for a password twice makes perfect sense (the user can't see what they're typing) but if you want to validate an email address the only reliable way is to send a message to the address specified containing further details for signup.

  5. #5
    SitePoint Zealot themissingelf's Avatar
    Join Date
    Nov 2001
    Location
    UK
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with what your saying and I also copy & paste in these situations, however, I plan to make the check an optional one for those people that are less than confident about their keyboard skills and want the context sensitive "spellcheck".

    Elf


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •