validation

package
v0.0.0-...-897bb11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MobileRegex      = regexp.MustCompile(`^(?:07|\+?447)\d{9}$`)
	NonUKMobileRegex = regexp.MustCompile(`^\+\d{4,15}$`)
)

Functions

This section is empty.

Types

type AddressChecker

type AddressChecker interface {
	CheckAddress(string, *place.Address) FormattableError
}

type BoolChecker

type BoolChecker interface {
	CheckBool(string, bool) FormattableError
}

type CustomError

type CustomError struct {
	Label string
}

func (CustomError) Format

func (e CustomError) Format(l Localizer) string

type DateChecker

type DateChecker interface {
	CheckDate(string, date.Date) FormattableError
}

type DateMissingCheck

type DateMissingCheck struct{}

func DateMissing

func DateMissing() DateMissingCheck

func (DateMissingCheck) CheckDate

func (c DateMissingCheck) CheckDate(label string, date date.Date) FormattableError

type DateMissingError

type DateMissingError struct {
	Label string
	// need to highlight the correct fields, if all then EnterError should be used
	MissingDay   bool
	MissingMonth bool
	MissingYear  bool
}

func (DateMissingError) Format

func (e DateMissingError) Format(l Localizer) string

type DateMustBePastCheck

type DateMustBePastCheck struct{}

func DateMustBePast

func DateMustBePast() DateMustBePastCheck

func (DateMustBePastCheck) CheckDate

func (c DateMustBePastCheck) CheckDate(label string, value date.Date) FormattableError

type DateMustBePastError

type DateMustBePastError struct {
	Label string
}

func (DateMustBePastError) Format

func (e DateMustBePastError) Format(l Localizer) string

type DateMustBeRealCheck

type DateMustBeRealCheck struct{}

func DateMustBeReal

func DateMustBeReal() DateMustBeRealCheck

func (DateMustBeRealCheck) CheckDate

func (c DateMustBeRealCheck) CheckDate(label string, value date.Date) FormattableError

type DateMustBeRealError

type DateMustBeRealError struct {
	Label string
}

func (DateMustBeRealError) Format

func (e DateMustBeRealError) Format(l Localizer) string

type EmailCheck

type EmailCheck struct{}

func Email

func Email() EmailCheck

func (EmailCheck) CheckString

func (c EmailCheck) CheckString(label, value string) FormattableError

type EmailError

type EmailError struct {
	Label string
}

func (EmailError) Format

func (e EmailError) Format(l Localizer) string

type EmptyCheck

type EmptyCheck struct{}

func Empty

func Empty() EmptyCheck

func (EmptyCheck) CheckString

func (c EmptyCheck) CheckString(label, value string) FormattableError

type EnterError

type EnterError struct {
	Label string
}

func (EnterError) Format

func (e EnterError) Format(l Localizer) string

type ErrorChecker

type ErrorChecker interface {
	CheckError(label string, value error) FormattableError
}

type Field

type Field struct {
	Name  string
	Error FormattableError
}

type FormattableError

type FormattableError interface {
	Format(Localizer) string
}

type List

type List []Field

func With

func With(name string, error FormattableError) List

func (*List) Add

func (l *List) Add(name string, error FormattableError)

func (*List) Address

func (l *List) Address(name, label string, value *place.Address, checks ...AddressChecker)

func (List) Any

func (l List) Any() bool

func (*List) Bool

func (l *List) Bool(name, label string, value bool, checks ...BoolChecker)

func (*List) Date

func (l *List) Date(name, label string, value date.Date, checks ...DateChecker)

func (*List) Error

func (l *List) Error(name, label string, value error, checks ...ErrorChecker)

func (List) Format

func (l List) Format(localizer Localizer, name string) string

func (List) Has

func (l List) Has(name string) bool

func (List) HasForDate

func (l List) HasForDate(name, part string) bool

func (List) None

func (l List) None() bool

func (*List) Options

func (l *List) Options(name, label string, value []string, checks ...OptionsChecker)

func (*List) String

func (l *List) String(name, label, value string, checks ...StringChecker)

func (List) With

func (l List) With(name string, error FormattableError) List

type Localizer

type Localizer interface {
	Format(string, map[string]any) string
	T(string) string
}

type MobileCheck

type MobileCheck struct {
	// contains filtered or unexported fields
}

func Mobile

func Mobile() MobileCheck

func NonUKMobile

func NonUKMobile() MobileCheck

func (MobileCheck) CheckString

func (c MobileCheck) CheckString(label, value string) FormattableError

func (MobileCheck) ErrorLabel

func (c MobileCheck) ErrorLabel(label string) MobileCheck

type MobileError

type MobileError struct {
	Label string
}

func (MobileError) Format

func (e MobileError) Format(l Localizer) string

type OptionsChecker

type OptionsChecker interface {
	CheckOptions(string, []string) FormattableError
}

type SelectCheck

type SelectCheck struct {
	// contains filtered or unexported fields
}

func Select

func Select(in ...string) SelectCheck

func (SelectCheck) CheckOptions

func (c SelectCheck) CheckOptions(label string, value []string) FormattableError

func (SelectCheck) CheckString

func (c SelectCheck) CheckString(label string, value string) FormattableError

func (SelectCheck) CustomError

func (c SelectCheck) CustomError() SelectCheck

type SelectError

type SelectError struct {
	Label string
}

func (SelectError) Format

func (e SelectError) Format(l Localizer) string

type SelectedCheck

type SelectedCheck struct {
	// contains filtered or unexported fields
}

func Selected

func Selected() SelectedCheck

func (SelectedCheck) CheckAddress

func (c SelectedCheck) CheckAddress(label string, value *place.Address) FormattableError

func (SelectedCheck) CheckBool

func (c SelectedCheck) CheckBool(label string, value bool) FormattableError

func (SelectedCheck) CheckError

func (c SelectedCheck) CheckError(label string, err error) FormattableError

func (SelectedCheck) CheckOptions

func (c SelectedCheck) CheckOptions(label string, value []string) FormattableError

func (SelectedCheck) CustomError

func (c SelectedCheck) CustomError() SelectedCheck

type StringChecker

type StringChecker interface {
	CheckString(label, value string) FormattableError
}

type StringLengthCheck

type StringLengthCheck struct {
	// contains filtered or unexported fields
}

func StringLength

func StringLength(length int) StringLengthCheck

func (StringLengthCheck) CheckString

func (c StringLengthCheck) CheckString(label, value string) FormattableError

type StringLengthError

type StringLengthError struct {
	Label  string
	Length int
}

func (StringLengthError) Format

func (e StringLengthError) Format(l Localizer) string

type StringTooLongCheck

type StringTooLongCheck struct {
	// contains filtered or unexported fields
}

func StringTooLong

func StringTooLong(length int) StringTooLongCheck

func (StringTooLongCheck) CheckString

func (c StringTooLongCheck) CheckString(label, value string) FormattableError

type StringTooLongError

type StringTooLongError struct {
	Label  string
	Length int
}

func (StringTooLongError) Format

func (e StringTooLongError) Format(l Localizer) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL