Why does filter_var($email, FILTER_VALIDATE_EMAIL) allow test@test?

前端 未结 4 1786
忘了有多久
忘了有多久 2021-02-08 07:00

I was just setting up the validation for a form in which I decided to try using the filter_var function to check the validity of my email address. I can not find out what filter

4条回答
  •  清歌不尽
    2021-02-08 07:59

    test@test is syntactically valid.

    From RFC 5321:

    In the case of a top-level domain used by itself in an email address, a single string is used without any dots.

    Only after this does it say:

    Only resolvable, fully-qualified domain names (FQDNs) are permitted when domain names are used in SMTP. In other words, names that can be resolved to MX RRs or address (i.e., A or AAAA) RRs (as discussed in Section 5) are permitted, as are CNAME RRs whose targets can be resolved, in turn, to MX or address RRs. Local nicknames or unqualified names MUST NOT be used.

    This does not necessarily preclude TLD-only domain names. In fact, run the following code:

    checkdnsrr('ua', 'MX') // Returns true

    getmxrr('ua', $array) // Returns true

    TLD-only domain names (can) have MX records and are in use: http://www.to/ is an example. And here's some valid TLD-only domain name email addresses:

    vince@ai

    paul@io

    root@km

    joost@tk

    admin@tt

    hostmaster@ua

    Source of example email addresses: Tony Finch – TLDs with MXs

提交回复
热议问题