Store and validate email addresses with optional domain restrictions
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.
import "github.com/pocketbase/pocketbase/core"field := &core.EmailField{ Name: "email", Required: true,}collection.Fields.Add(field)// Set field valuerecord.Set("email", "user@example.com")
field := &core.EmailField{ Name: "workEmail", Required: true, OnlyDomains: []string{"company.com", "subsidiary.com"},}collection.Fields.Add(field)// This will validate successfullyrecord.Set("workEmail", "john@company.com")// This will fail validationrecord.Set("workEmail", "john@gmail.com")
field := &core.EmailField{ Name: "email", Required: true, ExceptDomains: []string{"tempmail.com", "throwaway.email"},}collection.Fields.Add(field)// This will validate successfullyrecord.Set("email", "user@gmail.com")// This will fail validationrecord.Set("email", "user@tempmail.com")