Validate Email is from Specific Domain

We have a php form that collects some basic information ...

- email
- firstname
- lastname
- company

This signup form is specific to one client so we want to block everyone else from signing up.

Examples of correct email addresses ...

Any address that does not use '' is incorrect and should throw up an error ...

"sorry - that email is not valid"

We want the check to be made before form submission - so, after the user enters their email address and tabs to the next field.

Who is Participating?
Yes, I see. There is a problem with Sender.focus(); Replace it with: window.setTimeout(function(){Sender.focus();},10);
Om PrakashCommented:
//Add following javascript validation
        var str= document.form1.emailfield.value;
        var a2 = str.toLowerCase();
        if(a2.indexOf("") == -1)
              alert("sorry - that email is not valid");
<input type='text' name='email' id='email' onchange='validateEmail(this)'>

function validateEmail(Sender){
  var validSuffix = "";
  var emailSuffix = Sender.value.substring(Sender.value.indexOf("@")+1);

  if(validSuffix != emailSuffix){
      alert("sorry - that email is not valid");
      Sender.value = "";
poldingsAuthor Commented:
That works great. Just one thing to make it a bit more user friendly pls ...

How can I adapt it so the focus is back on the 'email' field after the alert has closed?
poldingsAuthor Commented:
Perfect. Works a treat.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.