0

My form is sending even without the user even put a "@" in the email field.

how can I do to leave the field with red border if no "@"?

<input type="text" name="Name" placeholder="Nome..." class="quote-form-element" />
<input type="text" name="City" placeholder="Cidade/UF..." class="quote-form-element quote-form-client-email last" />
<input type="text" name="phone" placeholder="Telefone..." class="quote-form-element" />
<input type="text" name="email" placeholder="E-mail..." class="quote-form-element quote-form-client-email last" />

1 Answers1

0

Make it into a function and use regular expressions to check if the email is valid.

function emailVal(email){
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if (reg.test(emailField.value) == false) 
    {
        //invalid email
        return false;
    }

    return true;

 }

On the textbox use:

<input type="email" onblur="emailVal(this)">

Now if emailVal() returns false, do a red border around the textbox.

twodee
  • 606
  • 5
  • 24