svelte-forms icon indicating copy to clipboard operation
svelte-forms copied to clipboard

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

Open jhwheeler opened this issue 1 year ago • 0 comments

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 avatar Sep 11 '24 16:09 jhwheeler