Verify that the value is an email address or not. >>> s = Schema(Email()) >>> with raises(MultipleInvalid, 'expected an email address'): ... s("a.com") >>> with raises(MultipleInvalid, 'expected an email address'): ... s("a@.com") >>> with raises(MultipleInvalid, 'expect
(v)
| 495 | |
| 496 | @message('expected an email address', cls=EmailInvalid) |
| 497 | def Email(v): |
| 498 | """Verify that the value is an email address or not. |
| 499 | |
| 500 | >>> s = Schema(Email()) |
| 501 | >>> with raises(MultipleInvalid, 'expected an email address'): |
| 502 | ... s("a.com") |
| 503 | >>> with raises(MultipleInvalid, 'expected an email address'): |
| 504 | ... s("a@.com") |
| 505 | >>> with raises(MultipleInvalid, 'expected an email address'): |
| 506 | ... s("a@.com") |
| 507 | >>> s('t@x.com') |
| 508 | 't@x.com' |
| 509 | """ |
| 510 | try: |
| 511 | if not v or "@" not in v: |
| 512 | raise EmailInvalid("Invalid email address") |
| 513 | user_part, domain_part = v.rsplit('@', 1) |
| 514 | |
| 515 | if not (USER_REGEX.match(user_part) and DOMAIN_REGEX.match(domain_part)): |
| 516 | raise EmailInvalid("Invalid email address") |
| 517 | return v |
| 518 | except: # noqa: E722 |
| 519 | raise ValueError |
| 520 | |
| 521 | |
| 522 | @message('expected a fully qualified domain name URL', cls=UrlInvalid) |
searching dependent graphs…