Skip to content
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

[BUG] Email validation excludes valid email addresses with TLDs longer than 7 characters #119

Open
jhwheeler opened this issue Sep 11, 2024 · 0 comments · May be fixed by #120
Open

[BUG] Email validation excludes valid email addresses with TLDs longer than 7 characters #119

jhwheeler opened this issue Sep 11, 2024 · 0 comments · May be fixed by #120
Assignees
Labels
bug Something isn't working

Comments

@jhwheeler
Copy link

jhwheeler commented Sep 11, 2024

Describe the bug

The email validator has a character length restriction between 2 and 7 characters.

However, there are valid TLDs that are longer than that, e.g. .technology, .international, .photography, .university, .solutions, .foundation, etc. In this list of all currently valid TLDs, there are many that are longer than 7 characters; it seems that the maximum length currently in use is 24. In fact, TLDs per the ICANN spec can be up to 63 characters, according to MDN.

To Reproduce

Steps to reproduce the behavior:

  1. Enter an email with a TLD longer than 7 characters, such as .foundation, into an input using the email validator
  2. Try to submit your form
  3. Email validation error is triggered

Expected behavior

No error should be triggered by valid TLDs (i.e. those with lengths up to 63 characters).

Additional context

export function email(): Validator {
	return (value: any) => {
                // The `{2,7}` here is what should be updated to `{2,63}`
		const regex = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
		return { valid: Boolean(value) && regex.test(value), name: 'not_an_email' };
	};
}
@jhwheeler jhwheeler added the bug Something isn't working label Sep 11, 2024
@jhwheeler jhwheeler linked a pull request Sep 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants