validator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 2 Imported by: 2

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])?)*$")

Functions

func Matches

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

Matches checks if the given value matches the regular expression pattern. It returns true if there is a match, otherwise false.

func PermittedValue

func PermittedValue[T comparable](value T, permittedValues ...T) bool

PermittedValue checks if the given value is present in the list of permitted values. It returns true if the value is found, otherwise false.

func Unique

func Unique[T comparable](values []T) bool

Unique checks if the given slice of values contains only unique elements. It returns true if all elements are unique, and false otherwise.

Types

type Validator

type Validator struct {
	Errors map[string]string
}

func New

func New() *Validator

New creates a new instance of the Validator struct.

func (*Validator) AddError

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

AddError adds an error message to the Validator's Errors map. If the given key does not exist in the Errors map, it adds the key-value pair to the map. The key is used to identify the error, and the message provides a description of the error.

func (*Validator) Check

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

Check checks if the given condition is false and adds an error to the validator if it is.

func (*Validator) Valid

func (v *Validator) Valid() bool

Valid checks if the Validator instance has any errors. It returns true if there are no errors, otherwise false.

Jump to

Keyboard shortcuts

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