validation

package
v2.0.0-...-4e8a7ef Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DBValidators = map[*regexp.Regexp]func(match []string, value *generic.Value, stmt *gorm.Statement, field *schema.Field) error{
	regexp.MustCompile("^unique$"):          uniqueValidator,
	regexp.MustCompile("^unique:(.+)$"):     uniqueColumnsValidator,
	regexp.MustCompile("^fk$"):              foreignKeyValidator,
	regexp.MustCompile("^enum$"):            enumValidator,
	regexp.MustCompile(`^before\((\w+)\)$`): beforeValidator,
	regexp.MustCompile(`^after\((\w+)\)$`):  afterValidator,
}
View Source
var Validators = map[*regexp.Regexp]func(match []string, value *generic.Value) error{
	regexp.MustCompile("(?i)^text$"):                              textValidator,
	regexp.MustCompile("(?i)^name$"):                              nameValidator,
	regexp.MustCompile("(?i)^alpha$"):                             alphaValidator,
	regexp.MustCompile("(?i)^latin$"):                             latinValidator,
	regexp.MustCompile("(?i)^name$"):                              nameValidator,
	regexp.MustCompile("(?i)^digit$"):                             digitValidator,
	regexp.MustCompile("(?i)^alphanumeric$"):                      alphaNumericValidator,
	regexp.MustCompile("(?i)^required$"):                          requiredValidator,
	regexp.MustCompile("(?i)^email$"):                             emailValidator,
	regexp.MustCompile(`(?i)^regex\((.*)\)$`):                     regexValidator,
	regexp.MustCompile(`(?i)^len(>|<|<=|>=|==|!=|<>|=)(\d+)$`):    lenValidator,
	regexp.MustCompile(`(?i)^(>|<|<=|>=|==|!=|<>|=)([+\-]?\d+)$`): numericalValidator,
	regexp.MustCompile(`(?i)^([+\-]?)int$`):                       intValidator,
	regexp.MustCompile(`(?i)^([+\-]?)float$`):                     floatValidator,
	regexp.MustCompile(`(?i)^password\((.*)\)$`):                  passwordValidator,
	regexp.MustCompile(`(?i)^domain$`):                            domainValidator,
	regexp.MustCompile(`(?i)^url$`):                               urlValidator,
	regexp.MustCompile(`(?i)^ip(v?4)?$`):                          ip4Validator,
	regexp.MustCompile(`(?i)^ipv?6$`):                             ip6Validator,
	regexp.MustCompile(`(?i)^cidr$`):                              cidrValidator,
	regexp.MustCompile(`(?i)^mac$`):                               macValidator,
	regexp.MustCompile(`(?i)^date$`):                              dateValidator,
	regexp.MustCompile(`(?i)^longitude`):                          longitudeValidator,
	regexp.MustCompile(`(?i)^latitude`):                           latitudeValidator,
	regexp.MustCompile(`(?i)^port$`):                              portValidator,
	regexp.MustCompile(`(?i)^json$`):                              jsonValidator,
	regexp.MustCompile(`(?i)^ISBN$`):                              isbnValidator,
	regexp.MustCompile(`(?i)^ISBN10$`):                            isbn10Validator,
	regexp.MustCompile(`(?i)^ISBN13$`):                            isbn13Validator,
	regexp.MustCompile(`(?i)^[credit[-_]?card$`):                  creditCardValidator,
	regexp.MustCompile(`(?i)^uuid$`):                              uuidValidator,
	regexp.MustCompile(`(?i)^upperCase$`):                         upperCaseValidator,
	regexp.MustCompile(`(?i)^lowerCase$`):                         lowerCaseValidator,
	regexp.MustCompile(`(?i)^rgb[-_]?color$`):                     _RGBColorValidator,
	regexp.MustCompile(`(?i)^rgba[-_]?color$`):                    _RGBAColorValidator,
	regexp.MustCompile(`(?i)^hex[-_]?color$`):                     _HEXColorValidator,
	regexp.MustCompile(`(?i)^hex$`):                               _HEXValidator,
	regexp.MustCompile(`(?i)^country[-_]?alpha[-_]?2$`):           _CountryAlpha2Validator,
	regexp.MustCompile(`(?i)^country[-_]?alpha[-_]?3`):            _CountryAlpha3Validator,
	regexp.MustCompile(`(?i)^btc[-_]?address`):                    _BTCAddressValidator,
	regexp.MustCompile(`(?i)^eth[-_]?address`):                    _ETHAddressValidator,
	regexp.MustCompile(`(?i)^cron`):                               cronValidator,
	regexp.MustCompile(`(?i)^duration`):                           durationValidator,
	regexp.MustCompile(`(?i)^time$`):                              timestampValidator,
	regexp.MustCompile(`(?i)^(unix[-_]?timestamp|unix[-_]?ts)$`):  unixTimestampValidator,
	regexp.MustCompile(`(?i)^timezone$`):                          timezoneValidator,
	regexp.MustCompile(`(?i)^e164$`):                              e164Validator,
	regexp.MustCompile(`(?i)^safe[-_]?html`):                      safeHTMLValidator,
	regexp.MustCompile(`(?i)^no[-_]?html$`):                       noHTMLValidator,
	regexp.MustCompile(`(?i)^phone$`):                             phoneValidator,
}

Functions

func Struct

func Struct(input interface{}, fields ...string) []error

func StructNonZeroFields

func StructNonZeroFields(input interface{}, fields ...string) []error

func Value

func Value(input interface{}, validation string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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