Why Does Html5 Form-Validation Allow Emails Without a Dot

Why does HTML5 form-validation allow emails without a dot?

Because a@b is a valid email address (eg localhost is a valid domain). See http://en.wikipedia.org/wiki/Email_address#Examples

Also, keep in mind that you should always do the input validation in server. The client side validation should be only for giving feedback to the user and not be relied on, since it can be easily bypassed.

Why does a@a pass built-in validation for an email input?

Hostnames do not have to have a domain associated with their TLD. A common example would be localhost.

How does HTML5 input type email works without top level domain name

Because bar is a valid hostname, which makes foo@bar a valid email address.

Chrome is not going to check for you whether the address or host are actually in use, only whether the semantics are correct.

See http://en.wikipedia.org/wiki/Email_address#Domain_part for examples of valid email addresses.

HTML5 Email validation should not allow email without . example aaa@aaa

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

Should email validation requires the domain part contains a dot?

The RFC 822, chapter 6, gives the specification of an address in augmented Backus-Naur Form (BNF):

addr-spec   =  local-part "@" domain
local-part = word *("." word)
domain = sub-domain *("." sub-domain)

Using this specification a@b is a valid address.

html5 e-mail validation failed

<form>
<input pattern="[a-zA-Z0-9.-_]{1,}@[a-zA-Z.-]{2,}[.]{1}[a-zA-Z]{2,}$"
type="text" required />
<input type="submit" value="Send" />
</form>

HTML5 Email input pattern attribute

This is a dual problem (as many in the world wide web world).

You need to evaluate if the browser supports html5 (I use Modernizr to do it). In this case if you have a normal form the browser will do the job for you, but if you need ajax/json (as many of everyday case) you need to perform manual verification anyway.

.. so, my suggestion is to use a regular expression to evaluate anytime before submit. The expression I use is the following:

var email = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/;

This one is taken from http://www.regular-expressions.info/ . This is a hard world to understand and master, so I suggest you to read this page carefully.



Related Topics



Leave a reply



Submit