validator

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 CanNotBe

func CanNotBe(value string, prefix string) bool

------------------------------------------------------

------------------------------------------------------ Cannot be

func Matches

func Matches(value string, rx *regexp.Regexp) bool

Matches() returns true if a value matches a provided compiled regular expression pattern.

func MaxChars

func MaxChars(value string, n int) bool

------------------------------------------------------

------------------------------------------------------ MaxChars() returns true if a value contains no more than n characters.

func MinChars

func MinChars(value string, n int) bool

------------------------------------------------------

------------------------------------------------------ MinChars() returns true if a value contains at least n characters.

func MustBeFromList

func MustBeFromList(value string, permittedValues ...string) bool

------------------------------------------------------

------------------------------------------------------

func MustBeJSON

func MustBeJSON(value string) bool

------------------------------------------------------

------------------------------------------------------

func MustBeOfType

func MustBeOfType(value string, typeToCheck string) bool

------------------------------------------------------

------------------------------------------------------

func MustBeXML

func MustBeXML(value string) bool

------------------------------------------------------

------------------------------------------------------

func MustNotContainBlanks

func MustNotContainBlanks(value string) bool

------------------------------------------------------

------------------------------------------------------ Must start with

func MustNotStartwith

func MustNotStartwith(value string, prefix string) bool

------------------------------------------------------

------------------------------------------------------ Must start with

func MustStartwith

func MustStartwith(value string, prefix string) bool

------------------------------------------------------

------------------------------------------------------ Must start with

func MustStartwithOneOf

func MustStartwithOneOf(value string, prefixs ...string) bool

------------------------------------------------------

------------------------------------------------------ Must start with One of

func NotBlank

func NotBlank(value string) bool

------------------------------------------------------

------------------------------------------------------ NotBlank() returns true if a value is not an empty string.

func PermittedInt

func PermittedInt(value int, permittedValues ...int) bool

------------------------------------------------------

------------------------------------------------------ PermittedInt() returns true if a value is in a list of permitted integers.

Types

type Validator

type Validator struct {
	FieldErrors    map[string]string `json:"field_error" db:"-" form:"-"`
	NonFieldErrors []string
}

------------------------------------------------------

------------------------------------------------------ Define a new Validator type which contains a map of validation errors for our form fields.

func (*Validator) AddFieldError

func (v *Validator) AddFieldError(key, message string)

------------------------------------------------------

------------------------------------------------------ AddFieldError() adds an error message to the FieldErrors map (so long as no entry already exists for the given key).

func (*Validator) AddNonFieldError

func (v *Validator) AddNonFieldError(message string)

------------------------------------------------------

------------------------------------------------------

func (*Validator) CheckField

func (v *Validator) CheckField(ok bool, key, message string)

------------------------------------------------------

------------------------------------------------------ CheckField() adds an error message to the FieldErrors map only if a validation check is not 'ok'.

func (*Validator) Valid

func (v *Validator) Valid() bool

------------------------------------------------------

------------------------------------------------------ Valid() returns true if the FieldErrors map doesn't contain any entries.

Jump to

Keyboard shortcuts

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