1

I created an input with the following mark-up:

<input name="contactEmail" type="email" required>

I added a CSS class for input:invalid which gives it a red border, and then tested it by inputting a@a as the value, and the field was marked valid. Why would that be a valid input for this when it's clearly not a valid email? Regarding valid values for an input of type email, MDN says:

In simple terms, this means username@domain.tld

But this obviously doesn't match any regex designed to look for that pattern. So...what gives?

Edit:

According to MDN, this is algorithm used for email validation in compliant browser:

/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

I haven't broken that apart yet, but a@a does indeed match it. So I guess the question becomes why does the regex all that to match?

temporary_user_name
  • 35,956
  • 47
  • 141
  • 220
  • [Can you have an email address with only the top level domain as the domain part?](https://serverfault.com/questions/721927/can-you-have-an-email-address-with-only-the-top-level-domain-as-the-domain-part/721929) and [New gTLD Dotless Domain Names Prohibited](https://www.icann.org/news/announcement-2013-08-30-en). So while it is valid to have `a@a` according to the specs, it is prohibited according to the icann. But because ICANN could change its mind in future, you would develop a validator according to the specs. – t.niese Nov 22 '18 at 00:02

2 Answers2

3

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

Charles Stover
  • 1,132
  • 6
  • 13
  • 1
    `localhost` is a TLD ([rfc2606](https://tools.ietf.org/html/rfc2606)). But a TLD does not need to have the domain or subdomain part. So `a@com` could also be valid. – t.niese Nov 21 '18 at 23:59
  • [Can you have an email address with only the top level domain as the domain part?](https://serverfault.com/questions/721927/can-you-have-an-email-address-with-only-the-top-level-domain-as-the-domain-part/721929) – t.niese Nov 22 '18 at 00:02
-1

There's nothing invalid about it. It's as simple as that.

There's no reason a mailbox can't be called a on the host a.

Brad
  • 159,648
  • 54
  • 349
  • 530