* Rules for validation are subset of rules listed here: https://emailregex.com/email-validation-summary/ */ Valid checks whether ths string is valid as a email address as defined by RFC 5321.
(addr string)
| 32 | // Valid checks whether ths string is valid as a email address as defined by |
| 33 | // RFC 5321. |
| 34 | func Valid(addr string) bool { |
| 35 | if len(addr) > 320 { // RFC 3696 says it's 320, not 255. |
| 36 | return false |
| 37 | } |
| 38 | |
| 39 | mbox, domain, err := Split(addr) |
| 40 | if err != nil { |
| 41 | return false |
| 42 | } |
| 43 | |
| 44 | // The only case where this can be true is "postmaster". |
| 45 | // So allow it. |
| 46 | if domain == "" { |
| 47 | return true |
| 48 | } |
| 49 | |
| 50 | return ValidMailboxName(mbox) && ValidDomain(domain) |
| 51 | } |
| 52 | |
| 53 | var validGraphic = map[rune]bool{ |
| 54 | '!': true, '#': true, |
no test coverage detected