Input email only display suggestions for EMAILS

1
Hello, I have an email input and for easy typing and everything else I would like a "self suggestion", but it is showing everything I have already typed with the letter G, for example, including names, things, emails and etc, I would like when I click on the field of the email it gives me the suggestion of only emails that I have already typed, would anyone know how to do this? And I would like to add a validation, to see if the user typed with @domain.com, and did this validation in the blur.

    
asked by anonymous 21.08.2017 / 19:58

3 answers

1

As requested in the comment, "Would you know how to disable the form button when the message appears?" in the response of Damon Dudek and for the reasons given in the comment on my response "Why is it a contact form, so if the client types a wrong email and even though the message appears, he can still click send and send the message by one -mail missing, disabling the button when having an invalid email he could not send! "

It is not necessary to disable the form button when the message appears, just put the validation on it too !!

Blur method on input id='email' and click on button type='submit'

function validateEmail(email) {
var re = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  return re.test(email);
}

function validate() {
  $("#result").text("");
  var email = $("#email").val();
  if (validateEmail(email)) {
//$("#result").text(email + " é valido :)");
//$("#result").css("color", "green");
return true;
  } else {
$("#result").text(email + " não é válido :(");
$("#result").css("color", "red");
return false;
  }
  
}

$(".validate").bind("blur", validate);
$("#validate").bind("click", validate);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><formaction="https://pt.stackoverflow.com/unanswered">
  <p>email:</p>
  <input id='email' class='validate'>
  <button type='submit' id='validate'>Submit!</button>
</form>

<h2 id='result'></h2>
  

The input type="email" is not supported by IE9 and earlier and Safari.

     

Apple's Safari ranks second to most used browsers, with 25.4 percent Font

Andhere'sanotherstatisticnolessdespicableforSafari Font

    
21.08.2017 / 21:42
2

E-mail suggestions for an email field are automatically made by browsers, you just have to give the email name for your input.

While email validation already exists a native feature of HMTL5, just set your input with type email:

<input type="email" name="email" />

Input types: link

    
21.08.2017 / 20:11
1

To validate is a bit different, like this:

<form action="">
    <input type="email" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$"/>
    <input type="submit"/>
</form>

Then you need to see if this pattern is correct.

Font

If you do not want any suggestions to appear use autocomplete=off

For custom suggestions, use Ajax .

    
21.08.2017 / 20:49