Open
Description
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:
- Enter an email with a TLD longer than 7 characters, such as
.foundation
, into an input using theemail
validator - Try to submit your form
- 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' };
};
}