Why does Input Type validation mail accept domains without a dot?

14

The input type[email] is intended to validate if the field is being populated with a valid email.

But I've been questioning a few times on some projects about why this field accepts some types of emails that are seemingly invalid.

Example:

[type=email]:invalid{
   color:red;
}
[type=email]:valid{
   color: green;
   border-color: lightgreen;
}
<input type="email" value="wallace@dominio-sem-ponto-com" />

<input type="email" value="wallace@xx" />

<input type="email" value="[email protected]" />

<input type="email" value="wallace" />

If you notice, none of the emails whose domain was without ".com" or ".net" was marked invalid.

Why does this happen?

Why was the "wallace@dominio-sem-ponto-com" email considered valid by the browser?

Is there a case where it would be valid to use a domain with no value after the point ( .com , .net , etc)?

    
asked by anonymous 23.01.2017 / 15:33

4 answers

11

Validation occurs only on account of @, domain is actually a name, eg: tassio @ domain , it does not necessarily need to be a sub domain (dotted), eg: tassio @ mydomain.com , in what situations can this occur? Within an intranet for example, or if the .br registry or other registration bodies release the registration of primary domains ai for example could register a domain " google ", to access the site would only use http://google and an example of Email would be contato@google .

    
24.01.2017 / 16:07
7

According to W3C :

  

The <input type="email"> is used for input fields that should contain   an email address.

     

Depending on browser support, the e-mail address can be automatically   validated when submitted.

     

Some smartphones recognize the email type, and adds ".com" to the   keyboard to match email input.

That is, this field uses input fields that must contain an email address and depending on the browser support, the email address can be automatically validated when sent.

Some smartphones recognize the type of e-mail and add ".com" to the keyboard to match the e-mail entry.

Why was the email " wallace@dominio-sem-ponto-com " considered valid by the browser?

Because in email validation using input type="email" , the value must begin with a letter or a number, followed by the symbol @ , then end with a domain name.

If you want to create your own validation rule, just use the attribute   pattern , it allows us to define our own rule to validate the input value using Regular Expressions (RegEx). If the value does not match the specified pattern, the entry will throw an error.

If you want the form to only accept [email protected], you can use it as follows:

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

Curiosity: On this site you can test validations with input.

    
02.02.2017 / 12:52
2

This occurs because input of type="email" accepts any text typed within itself with the only condition of having [email]@[domínio] in its value. To get around this and to have a better validation by the user side of the site user, it is recommended to use the pattern='' attribute that sets a default for the value of that input to be accepted, but care, client side, it can perform changes by the console to validate the form, then it is always recommended to do a server-side validation as well.

A good site to learn RegEx is the link .Click references to see which forms and expressions are used for validation in pattern

    
02.02.2017 / 12:25
2

In addition:

  

Is there a case where it would be valid to use a domain with no value after the dot (.com, .net, etc)?

Yes. We must remember that in local hosts (such as localhost for example) it would be totally valid to have emails like wallace@localhost . This does not mean that the email is invalid, but rather that it is not an ordinary "internet" email.

In intranet systems, for example, it may be common to use emails that do not contain conventional domains as we are accustomed to.

    
02.02.2017 / 13:32