Email validation w3schools
According to W3Schools, an email address is considered valid if it meets the following criteria:
- It starts with a letter (a-z or A-Z) or a number (0-9).
- It is followed by a period (.), hyphen (-), or underscore (_).
- It can contain letters (a-z or A-Z), numbers (0-9), periods (.), hyphens (-), underscores (_), and the at symbol (@).
- It must contain at least one character after the at symbol (@).
- The part before the at symbol (@) is called the local part, and it can contain up to 64 characters.
- The part after the at symbol (@) is called the domain, and it can contain up to 255 characters.
- The domain must contain at least one period (.) and cannot start or end with a period (.) or hyphen (-).
Here are some examples of valid email addresses:
And here are some examples of invalid email addresses:
- @example.com (missing local part)
- example..com (multiple periods in a row)
- [email protected] (hyphen at the beginning of the local part)
- example@example (missing period in the domain)
W3Schools also provides a regular expression that can be used to validate email addresses:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
This regular expression matches most common email address formats, but it's not foolproof and may not match all valid email addresses.