Configuration options
[]string
List of domains that are NOT allowed. Email addresses from these domains will fail validation. Cannot be set if
onlyDomains is specified.[]string
List of domains that are exclusively allowed. Email addresses must be from one of these domains. Cannot be set if
exceptDomains is specified.bool
default:"false"
When true, requires the field value to be a non-empty, valid email address.
Validation rules
The email field validates:- Format: Value must be a valid email address format
- Domain allowlist: If
onlyDomainsis set, email domain must be in the list - Domain blocklist: If
exceptDomainsis set, email domain must NOT be in the list - Required: If enabled, value cannot be empty
Go examples
- Basic usage
- Restrict to specific domains
- Block specific domains
- Multiple email fields
Database column type
Common use cases
Best practices
- Use
onlyDomainswhen you want to restrict to specific organizations or institutions - Use
exceptDomainsto block temporary/disposable email services - Email validation is case-insensitive for the domain part
- Consider email verification workflows in addition to format validation
- Store emails in lowercase for consistency in queries
Zero value
The zero value for email fields is an empty string"".