www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Form email address validation

  1. #1
    Join Date
    May 2007
    Posts
    12

    resolved [RESOLVED] Form email address validation

    Trying to ensure an email address is in the correct format, but it is showing the alert message regardless what is typed in.
    How do you check if a field is NOT in the correct format?? Currently im using the code below:


    Code:
    function validateOnSubmit()
          {
    
    var email = "";
    var theEmail = document.example.email.value;
    var atLoc = theEmail.indexOf("@",1);
    var dotLoc = theEmail.indexOf(".",atLoc+2);
    var len = theEmail.length;
    
    if (document.example.email.value=="")
    		{
    		  alert("Please enter your email address")
    		  document.example.email.focus();
    		  document.example.email.select();
    		  return false;
    		}
    
    
    	if (document.example.email != (atLoc > 1 && dotLoc > 1 && len > dotLoc+2))
    	{
    	  alert("Please check your email address")
    	  return false;
    	}
    
    return true;
    
    }

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,350
    Two questions:
    1. What kind of error(s),if any, are you getting in the JS console?
    2. Do you have your form and elements named 'example' and 'email'?

  3. #3
    Join Date
    May 2007
    Posts
    12
    Problem solved

    Code:
    if (!(atLoc > 1 && dotLoc > 1 && len > dotLoc+2))
    Thanks anyways

  4. #4
    Join Date
    Dec 2005
    Posts
    114

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles