Skip to main content
The email field stores a single email address string and validates it against the standard email format. You can optionally restrict which domains are allowed or blocked.

Configuration options

exceptDomains
[]string
List of domains that are NOT allowed. Email addresses from these domains will fail validation. Cannot be set if onlyDomains is specified.
onlyDomains
[]string
List of domains that are exclusively allowed. Email addresses must be from one of these domains. Cannot be set if exceptDomains is specified.
required
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 onlyDomains is set, email domain must be in the list
  • Domain blocklist: If exceptDomains is set, email domain must NOT be in the list
  • Required: If enabled, value cannot be empty
You cannot set both exceptDomains and onlyDomains at the same time. Choose one approach based on your use case.

Go examples

import "github.com/pocketbase/pocketbase/core"

field := &core.EmailField{
    Name:     "email",
    Required: true,
}

collection.Fields.Add(field)

// Set field value
record.Set("email", "user@example.com")

Database column type

TEXT DEFAULT '' NOT NULL

Common use cases

field := &core.EmailField{
    Name:        "corporateEmail",
    Required:    true,
    OnlyDomains: []string{"acmecorp.com"},
}

Best practices

  • Use onlyDomains when you want to restrict to specific organizations or institutions
  • Use exceptDomains to 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 "".