Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DisposableList = map[string]struct{}{}/* 3418 elements not displayed */
DisposableList is the list of domains that are considered to be from disposable email service providers. See: https://github.com/martenson/disposable-email-domains.
NOTE: To update the list, refer to the 'update' sub-package.
var ErrInvalidEmail = errors.New("invalid email")
ErrInvalidEmail is returned if the email address is invalid.
Functions ¶
func ValidateDomain ¶
ValidateDomain returns true if the domain component of an email address is valid. domain must be already lower-case and white-space trimmed. This function only performs a basic check and is not authoritative. For domains containing unicode characters, you must perform punycode conversion beforehand. See: https://godoc.org/golang.org/x/net/idna#ToASCII
Types ¶
type ParsedEmail ¶
type ParsedEmail struct { // Email represents the input email (after white-space has been trimmed). Email string // Preferred represents the local-part in the way the user seems to prefer it. // For example if the local-part is case-insensitive, the user may prefer their // email address all upper-case even if it does not matter. Preferred string // Normalized represents the local-part normalized such that it can be // compared for uniqueness. // // For gmail, since john.smith@gmail.com, johnsmith@gmail.com, and JohnSmith@gmail.com // are all equivalent, the normalized local-part is 'johnsmith'. Normalized string // Extra represents extra information that is domain specific. // // Example: gmail ignores all characters after the first '+' in the local-part. // // adam+junk@gmail.com => adam@gmail.com (Extra: junk) Extra string // Disposable is true if the email address is detected to be from // a disposable email service. // // See: https://github.com/martenson/disposable-email-domains Disposable bool // Domain represents the component after the '@' character. // It is lower-cased since it's case-insensitive. Domain string // LocalPart represents the component before the '@' character. LocalPart string }
ParsedEmail returns a parsed email address.
An email address is made up of 3 components: <local-part>@<domain>. The local-part is case-sensitive according to the specs, but most (if not all) reputable email services will treat it as case-insensitive. The domain is case-insensitive.
func ParseEmail ¶
func ParseEmail(email string, caseSensitive ...bool) (ParsedEmail, error)
ParseEmail parses a given email address. Set caseSensitive to true if you want the local-part to be considered case-sensitive. The default value is false. Basic email validation is performed but it is not comprehensively checked.
See https://github.com/badoux/checkmail for a more robust validation solution.
See also https://davidcel.is/posts/stop-validating-email-addresses-with-regex.