I’m working on a regex for email verification.
This is what I have so far:
(?!^.*([._%+$-])1+.*$)^[a-zA-Z0-9][a-zA-Z0-9._%+$-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,7}$
I’ve gotten it to fulfill all these requirements:
- Consecutive periods (note, multiple periods can occur in address, they have to be separated by valid characters). Example [email protected]
- User names starting with a special character. Example #[email protected]
- User names with two special characters in a row. Example [email protected]
- Suffix name minimum length is 2. Example of invalid length: [email protected]
- Suffix maximum length is 7. Example of invalid length: [email protected]
But I am stuck on this last one:
- User name special character cannot follow period. Example customer.name.#[email protected]
I’ve attempted to add a second negative lookahead like this but I can’t get it to work correctly.:
(?!^.*([._%+-])1+.*$)(?!^.*(.)2+([._%+-])$)^[a-zA-Z0-9][a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,7}$
Any help is MUCH appreciated!
2
Answers
This regex should do what you want
You can try this:
See: https://regex101.com/r/4IYjU9/1