Skip to content

Is email validation outdated? #25186

Closed
Closed

Description

I'm submitting a...

[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

According to #18985, EMAIL_REGEXP must match the HTML spec.

Current version:

/^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[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])?)*$/

WHATWG version

/^[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])?)*$/

The WHATWG version is ~50 characters shorter than the current version.

I think the EMAIL_REGEXP is outdated. But if the current version is correct, the reason of the difference should be documented.

Activity

  1. gkalpak commented on Jul 29, 2018

    @gkalpak
    Member

    It's not outdated. It is an enhanced version 😁
    Basically, the email regex is ported over from AngularJS.

    A little background:

    A while back, the AngularJS regex looked almost identical to the WHATWG one (save for some domain name length restrictions).

    Then, in angular/angular.js@f3f5cf72e, the regex was enhanced to incorporate more RFC rules (e.g. related to domain names, etc). The commit message has more details.

    There is no such thing as a perfect email regex, so either one is as good imo.
    👍 for documenting what it does, though (even if just a high-level overview; one can always find the full details in the source code 😁).

  2. added this to the needsTriage milestone on Jul 30, 2018
  3. added
    feature
    on Jul 30, 2018
  4. modified the milestones: needsTriage, Backlog on Jul 30, 2018
  5. Naveen562117 commented on Aug 2, 2018

    @Naveen562117

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

    validators pattern for email

  6. mlc-mlapis commented on Aug 2, 2018

    @mlc-mlapis
    Contributor

    @Naveen562117 ... on a project you usually have your own validation set of validators (mainly because of your own rules for returned errors data structures) where the built in ones you wrap into (+ maybe enhance by your concrete needs).

  7. Naveen562117 commented on Aug 2, 2018

    @Naveen562117

    "validators.email" is accepting the
    email ID such as
    "example@gmail"
    which is invalid without .com at the end
    [email protected]
    is the valid
    this was the issue i found

    and the solution i for this issue is this:
    Validators.pattern ('([a-zA-Z0-9.!#$%&’*+/=?^_{|}~-]+@[a-zA-Z0-9-]+[.](?:\[a-zA-Z0-9-]+))')

    which is accepting the email id

  8. trotyl commented on Aug 2, 2018

    @trotyl
    Contributor

    @Naveen562117 example@gmail is a valid email address which has been answered for many years:

    https://stackoverflow.com/questions/20573488/why-does-html5-form-validation-allow-emails-without-a-dot

    An application could use stricter rule for its business requirement, but that won't change what a valid email is.

  9. ponkys commented on Aug 2, 2018

    @ponkys

    It seems that the discussion here is over and the issue can be closed.

    [7/1/19] Update: There are reasons people have pointed out in this thread that makes me regret this comment. this issue should keep open.

  10. ponkys commented on Aug 9, 2018

    @ponkys

    @Maxkorz You are right about the tests and I agree with you but in terms of documentation, I think the Angular team doesn't need to explain everything they do if it takes a search on google to understand what a valid email is. Looking forward to the final decision about this here.

  11. scottseeker commented on Jan 7, 2019

    @scottseeker

    @ponkys Disagree. The email validator does not match the rules provided by the RFC (2822?). Because of that, I have no idea what their email validator does. On a project with very specific requirements it would be nice to know without guessing/checking.

    For instance their built in validator does not allow " or \ characters and fails against some international characters.

  12. ponkys commented on Jan 7, 2019

    @ponkys

    @scottseeker Thanks for pointing this out.

  13. self-assigned this
    on Sep 18, 2019
  14. added a commit that references this issue on Oct 7, 2019
    006af0b
  15. angular-automatic-lock-bot commented on Jun 2, 2021

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  16. locked and limited conversation to collaborators on Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: formsfeaturestate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions