8000 Allow setting a global custom regex for Angular's email validator · Issue #62548 · angular/angular · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Allow setting a global custom regex for Angular's email validator #62548
@shimonsalamon

Description

@shimonsalamon

Which @angular/* package(s) are relevant/related to the feature request?

No response

Description

This topic has been discussed multiple times (#16544, #26395, #32788): Angular’s built-in Validators.email is intentionally permissive (accepts emails like a@a). Many developers find it insufficient for stricter email-validation needs in production apps.

Proposed solution

Introduce an injectable token (EMAIL_VALIDATOR_PATTERN) to allow globally setting a custom regex pattern for email validation, configured once in main.ts:

// main.ts
providers: [
  { provide: EMAIL_VALIDATOR_PATTERN, useValue: /^[^@\s]+@[^@\s]+\.[^@\s]{2,}$/ }
]

If provided, Angular's built-in Validators.email would automatically use this custom pattern.

Alternatives considered

The current workaround is creating custom validators individually in each form or field, resulting in repetitive and error-prone implementations across applications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0