Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var EmailRX = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
Use the regexp.MustCompile() function to parse a regular expression pattern for sanity checking the format of an email address. This returns a pointer to a 'compiled' regexp.Regexp type, or panics in the event of an error. Parsing this pattern once at startup and storing the compiled *regexp.Regexp in a variable is more performant than re-parsing the pattern each time we need it.
Functions ¶
func Matches ¶
Matches() returns true if a value matches a provided compiled regular expression pattern.
func PermittedValue ¶
func PermittedValue[T comparable](value T, permittedValues ...T) bool
PermittedValue() returns true if a value is in a list of specific permitted values.
Types ¶
type Validator ¶
Define a new Validator struct which contains a map of validation error messages for our form fields.
func (*Validator) AddFieldError ¶
AddFieldError() adds an error message to the FieldErrors map (so long as no entry already exists for the given key).
func (*Validator) AddNonFieldError ¶
Create an AddNonFieldError() helper for adding error messages to the new NonFieldErrors slice.
func (*Validator) CheckField ¶
CheckField() adds an error message to the FieldErrors map only if a validation check is not 'ok'.