validators

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: BSD-1-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VAR_PREFIX = "<<"
	VAR_SUFFIX = ">>"
	NameInt    = "int"
	NameString = "string"
	NameSlug   = "slug"
	NameUUID   = "uuid"
	NameAny    = "any"
	NameHex    = "hex"
	NameEmail  = "email"
	NamePhone  = "phone"
	NameBool   = "bool"
	NameFloat  = "float"
)
View Source
const (
	// Match any character
	REGEX_ANY = ".+"
	// Match any number
	REGEX_NUM = "[0-9]+"
	// Match any string
	REGEX_STR = "[a-zA-Z]+"
	// Match any hex number
	REGEX_HEX = "[0-9a-fA-F]+"
	// Match any UUID
	REGEX_UUID = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
	// Match any alphanumeric string
	REGEX_ALPHANUMERIC = "[0-9a-zA-Z_-]+"
	// Match any email address
	REGEX_EMAIL = `(?:[a-z0-9!#$%&'*+/=?^_` + "`" + `{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_` + "`" + `{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])`
	// Match any phone number
	REGEX_PHONE = `^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$`
	// Match any boolean
	REGEX_BOOL = "true|false|True|False|TRUE|FALSE|1|0"
	// Match any float
	REGEX_FLOAT = `\d+\.\d+|\d+,\d+`
)

Variables

This section is empty.

Functions

func PasswordStrength

func PasswordStrength(password FormValue) error

Checks if: - password is at least 8 characters long - password is at most 64 characters long - password contains at least one uppercase letter - password contains at least one lowercase letter - password contains at least one digit - password contains at least one non-digit - password does not contain any whitespace

func Regex

func Regex(regex string) func(value FormValue) error

Matches regex, Also matches custom strings, Example: Regex("<<email>>")("email") -> errors.New("not a match") Example: Regex("<<float>>")("0.01") -> nil

Types

type FormValue added in v1.0.6

type FormValue interface {
	IsFile() bool
	Value() string
	File() (string, io.ReadCloser)
}

type Validator

type Validator func(FormValue) error

func Length

func Length(min, max int) Validator

Check if the string is at least min and at most max.

func MaxLength

func MaxLength(max int) Validator

MaxLength returns a validator that checks if the length of the string is at most max.

func MinLength

func MinLength(min int) Validator

MinLength returns a validator that checks if the length of the string is at least min.

func New

func New(validators ...Validator) []Validator

Jump to

Keyboard shortcuts

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