Skip to content

fix: update email regex to support special characters #12181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 29, 2025

Conversation

grenhall
Copy link
Contributor

@grenhall grenhall commented Apr 22, 2025

What?

It's impossible to create a user with special characters in their email in Payload CMS 3.35.0.

The issue is that currently the regex looks like this:

...payload/packages/payload/src/fields/validations.ts (line 202-203):
const emailRegex = /^(?!...)[\w.%+-]+@a-z0-9?(?:.a-z0-9?).[a-z]{2,}$/i

This allows users that have the following characters in their email to be created:
%, ., +, -

The regex needs to get updated to the following:

const emailRegex = /^(?!...)[\w!#$%&'+/=?^{|}~.-]+@a-z0-9?(?:.a-z0-9?)*.[a-z]{2,}$/i`

This way all special characters `!#$%&'*+/=?^_{|}~.-`` are hereby OK to have in the email.

I've added more test-cases to cover a couple of more scenarios in the forked repo.

Why?

The regex is missing some special characters that are allowed according to standards.

How?

  • Go to the admin ui and try to create a user with any of the newly added special characters meaning (!#$%&'*+/=?^_{|}~.-`)
  • You should get a validation error. However with the addition of the above code it should all check out.

Fixes #
#12180

@grenhall grenhall changed the title fix: Email regex update to support special characters fix: email regex update to support special characters Apr 22, 2025
jacobsfletch
jacobsfletch previously approved these changes Apr 22, 2025
@jacobsfletch jacobsfletch changed the title fix: email regex update to support special characters fix: update email regex to support special characters Apr 29, 2025
@jacobsfletch jacobsfletch merged commit 8fee016 into payloadcms:main Apr 29, 2025
78 checks passed
Copy link
Contributor

🚀 This is included in version v3.36.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants