Lessons · Regex · an address you validate by sending to it
An address you validate by sending to it
The real grammar for an email address is enormous, so a strict pattern refuses valid addresses -- and the only proof one works is that mail arrives.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
Plus-addressing, quoted local parts, new top-level domains. Every hand-written email pattern eventually turns away a real customer.
How to think about it
Check the shape loosely -- something, an @, something with a dot -- to catch typos, and let a confirmation email do the validating.
Worked example
bool(re.fullmatch(r'[^@]+@[^@]+\.\w+', 'ada+billing@example.com'))A loose check accepts plus-addressing, which is legal and widely used.
bool(re.fullmatch(r'[a-z]+@[a-z]+\.[a-z]{2,3}', 'ada+billing@example.com'))A strict one refuses a real customer.Your turn
Accept the shape loosely enough for a real address.
bool(re.fullmatch(r'[^@]+@[^@]+\.+', 'ada+billing@example.com'))
Test a pattern against real text
The trap
The strict pattern feels more responsible and is the one that loses you sign-ups.
Practise an address you validate by sending to it on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.