validator

package
v0.0.0-...-cddd2eb Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Filename: internal/validator/validator.go

Index

Constants

This section is empty.

Variables

View Source
var (
	PasswordNumberRX  = regexp.MustCompile("[0-9]")
	PasswordUpperRX   = regexp.MustCompile("[A-Z]")
	PasswordLowerRX   = regexp.MustCompile("[a-z]")
	PasswordSpecialRX = regexp.MustCompile("[!@#~$%^&*()+|_]")
	PasswordMinLength = 8
	PasswordMaxLength = 72
)

Password complexity regular expressions

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

emailRX is a regular expression for validating email addresses

Functions

This section is empty.

Types

type Validator

type Validator struct {
	Errors map[string]string
}

Validator Structure to hold validation errors

func New

func New() *Validator

New creates a new Validator instance

func (*Validator) AddError

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

AddError adds an error message for a specific field if it doesn't already exist

func (*Validator) Check

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

Check adds an error message for a field if the condition is false

func (*Validator) IsEmpty

func (v *Validator) IsEmpty() bool

IsEmpty checks if there are any validation entries

func (*Validator) Matches

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

Matches checks if a value matches a given regular expression

func (*Validator) Permitted

func (v *Validator) Permitted(value string, permittedValues ...string) bool

Permitted checks if a value is in a list of permitted values

Jump to

Keyboard shortcuts

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