Categorygithub.com/asaskevich/govalidator
modulepackage
11.0.1+incompatible
Repository: https://github.com/asaskevich/govalidator.git
Documentation: pkg.go.dev

# README

govalidator

Gitter GoDoc Build Status Coverage Go Report Card GoSearch Backers on Open Collective Sponsors on Open Collective FOSSA Status

A package of validators and sanitizers for strings, structs and collections. Based on validator.js.

Installation

Make sure that Go is installed on your computer. Type the following command in your terminal:

go get github.com/asaskevich/govalidator

or you can get specified release of the package with gopkg.in:

go get gopkg.in/asaskevich/govalidator.v10

After it the package is ready to use.

Import package in your project

Add following line in your *.go file:

import "github.com/asaskevich/govalidator"

If you are unhappy to use long govalidator, you can do something like this:

import (
  valid "github.com/asaskevich/govalidator"
)

Activate behavior to require all fields have a validation tag by default

SetFieldsRequiredByDefault causes validation to fail when struct fields do not include validations or are not explicitly marked as exempt (using valid:"-" or valid:"email,optional"). A good place to activate this is a package init function or the main() function.

SetNilPtrAllowedByRequired causes validation to pass when struct fields marked by required are set to nil. This is disabled by default for consistency, but some packages that need to be able to determine between nil and zero value state can use this. If disabled, both nil and zero values cause validation errors.

import "github.com/asaskevich/govalidator"

func init() {
  govalidator.SetFieldsRequiredByDefault(true)
}

Here's some code to explain it:

// this struct definition will fail govalidator.ValidateStruct() (and the field values do not matter):
type exampleStruct struct {
  Name  string ``
  Email string `valid:"email"`
}

// this, however, will only fail when Email is empty or an invalid email address:
type exampleStruct2 struct {
  Name  string `valid:"-"`
  Email string `valid:"email"`
}

// lastly, this will only fail when Email is an invalid email address but not when it's empty:
type exampleStruct2 struct {
  Name  string `valid:"-"`
  Email string `valid:"email,optional"`
}

Recent breaking changes (see #123)

Custom validator function signature

A context was added as the second parameter, for structs this is the object being validated – this makes dependent validation possible.

import "github.com/asaskevich/govalidator"

// old signature
func(i interface{}) bool

// new signature
func(i interface{}, o interface{}) bool
Adding a custom validator

This was changed to prevent data races when accessing custom validators.

import "github.com/asaskevich/govalidator"

// before
govalidator.CustomTypeTagMap["customByteArrayValidator"] = func(i interface{}, o interface{}) bool {
  // ...
}

// after
govalidator.CustomTypeTagMap.Set("customByteArrayValidator", func(i interface{}, o interface{}) bool {
  // ...
})

List of functions:

func Abs(value float64) float64
func BlackList(str, chars string) string
func ByteLength(str string, params ...string) bool
func CamelCaseToUnderscore(str string) string
func Contains(str, substring string) bool
func Count(array []interface{}, iterator ConditionIterator) int
func Each(array []interface{}, iterator Iterator)
func ErrorByField(e error, field string) string
func ErrorsByField(e error) map[string]string
func Filter(array []interface{}, iterator ConditionIterator) []interface{}
func Find(array []interface{}, iterator ConditionIterator) interface{}
func GetLine(s string, index int) (string, error)
func GetLines(s string) []string
func HasLowerCase(str string) bool
func HasUpperCase(str string) bool
func HasWhitespace(str string) bool
func HasWhitespaceOnly(str string) bool
func InRange(value interface{}, left interface{}, right interface{}) bool
func InRangeFloat32(value, left, right float32) bool
func InRangeFloat64(value, left, right float64) bool
func InRangeInt(value, left, right interface{}) bool
func IsASCII(str string) bool
func IsAlpha(str string) bool
func IsAlphanumeric(str string) bool
func IsBase64(str string) bool
func IsByteLength(str string, min, max int) bool
func IsCIDR(str string) bool
func IsCRC32(str string) bool
func IsCRC32b(str string) bool
func IsCreditCard(str string) bool
func IsDNSName(str string) bool
func IsDataURI(str string) bool
func IsDialString(str string) bool
func IsDivisibleBy(str, num string) bool
func IsEmail(str string) bool
func IsExistingEmail(email string) bool
func IsFilePath(str string) (bool, int)
func IsFloat(str string) bool
func IsFullWidth(str string) bool
func IsHalfWidth(str string) bool
func IsHash(str string, algorithm string) bool
func IsHexadecimal(str string) bool
func IsHexcolor(str string) bool
func IsHost(str string) bool
func IsIP(str string) bool
func IsIPv4(str string) bool
func IsIPv6(str string) bool
func IsISBN(str string, version int) bool
func IsISBN10(str string) bool
func IsISBN13(str string) bool
func IsISO3166Alpha2(str string) bool
func IsISO3166Alpha3(str string) bool
func IsISO4217(str string) bool
func IsISO693Alpha2(str string) bool
func IsISO693Alpha3b(str string) bool
func IsIn(str string, params ...string) bool
func IsInRaw(str string, params ...string) bool
func IsInt(str string) bool
func IsJSON(str string) bool
func IsLatitude(str string) bool
func IsLongitude(str string) bool
func IsLowerCase(str string) bool
func IsMAC(str string) bool
func IsMD4(str string) bool
func IsMD5(str string) bool
func IsMagnetURI(str string) bool
func IsMongoID(str string) bool
func IsMultibyte(str string) bool
func IsNatural(value float64) bool
func IsNegative(value float64) bool
func IsNonNegative(value float64) bool
func IsNonPositive(value float64) bool
func IsNotNull(str string) bool
func IsNull(str string) bool
func IsNumeric(str string) bool
func IsPort(str string) bool
func IsPositive(value float64) bool
func IsPrintableASCII(str string) bool
func IsRFC3339(str string) bool
func IsRFC3339WithoutZone(str string) bool
func IsRGBcolor(str string) bool
func IsRegex(str string) bool
func IsRequestURI(rawurl string) bool
func IsRequestURL(rawurl string) bool
func IsRipeMD128(str string) bool
func IsRipeMD160(str string) bool
func IsRsaPub(str string, params ...string) bool
func IsRsaPublicKey(str string, keylen int) bool
func IsSHA1(str string) bool
func IsSHA256(str string) bool
func IsSHA384(str string) bool
func IsSHA512(str string) bool
func IsSSN(str string) bool
func IsSemver(str string) bool
func IsTiger128(str string) bool
func IsTiger160(str string) bool
func IsTiger192(str string) bool
func IsTime(str string, format string) bool
func IsType(v interface{}, params ...string) bool
func IsURL(str string) bool
func IsUTFDigit(str string) bool
func IsUTFLetter(str string) bool
func IsUTFLetterNumeric(str string) bool
func IsUTFNumeric(str string) bool
func IsUUID(str string) bool
func IsUUIDv3(str string) bool
func IsUUIDv4(str string) bool
func IsUUIDv5(str string) bool
func IsULID(str string) bool
func IsUnixTime(str string) bool
func IsUpperCase(str string) bool
func IsVariableWidth(str string) bool
func IsWhole(value float64) bool
func LeftTrim(str, chars string) string
func Map(array []interface{}, iterator ResultIterator) []interface{}
func Matches(str, pattern string) bool
func MaxStringLength(str string, params ...string) bool
func MinStringLength(str string, params ...string) bool
func NormalizeEmail(str string) (string, error)
func PadBoth(str string, padStr string, padLen int) string
func PadLeft(str string, padStr string, padLen int) string
func PadRight(str string, padStr string, padLen int) string
func PrependPathToErrors(err error, path string) error
func Range(str string, params ...string) bool
func RemoveTags(s string) string
func ReplacePattern(str, pattern, replace string) string
func Reverse(s string) string
func RightTrim(str, chars string) string
func RuneLength(str string, params ...string) bool
func SafeFileName(str string) string
func SetFieldsRequiredByDefault(value bool)
func SetNilPtrAllowedByRequired(value bool)
func Sign(value float64) float64
func StringLength(str string, params ...string) bool
func StringMatches(s string, params ...string) bool
func StripLow(str string, keepNewLines bool) string
func ToBoolean(str string) (bool, error)
func ToFloat(str string) (float64, error)
func ToInt(value interface{}) (res int64, err error)
func ToJSON(obj interface{}) (string, error)
func ToString(obj interface{}) string
func Trim(str, chars string) string
func Truncate(str string, length int, ending string) string
func TruncatingErrorf(str string, args ...interface{}) error
func UnderscoreToCamelCase(s string) string
func ValidateMap(inputMap map[string]interface{}, validationMap map[string]interface{}) (bool, error)
func ValidateStruct(s interface{}) (bool, error)
func WhiteList(str, chars string) string
type ConditionIterator
type CustomTypeValidator
type Error
func (e Error) Error() string
type Errors
func (es Errors) Error() string
func (es Errors) Errors() []error
type ISO3166Entry
type ISO693Entry
type InterfaceParamValidator
type Iterator
type ParamValidator
type ResultIterator
type UnsupportedTypeError
func (e *UnsupportedTypeError) Error() string
type Validator

Examples

IsURL
println(govalidator.IsURL(`http://user@pass:domain.com/path/page`))
IsType
println(govalidator.IsType("Bob", "string"))
println(govalidator.IsType(1, "int"))
i := 1
println(govalidator.IsType(&i, "*int"))

IsType can be used through the tag type which is essential for map validation:

type User	struct {
  Name string      `valid:"type(string)"`
  Age  int         `valid:"type(int)"`
  Meta interface{} `valid:"type(string)"`
}
result, err := govalidator.ValidateStruct(User{"Bob", 20, "meta"})
if err != nil {
	println("error: " + err.Error())
}
println(result)
ToString
type User struct {
	FirstName string
	LastName string
}

str := govalidator.ToString(&User{"John", "Juan"})
println(str)
Each, Map, Filter, Count for slices

Each iterates over the slice/array and calls Iterator for every item

data := []interface{}{1, 2, 3, 4, 5}
var fn govalidator.Iterator = func(value interface{}, index int) {
	println(value.(int))
}
govalidator.Each(data, fn)
data := []interface{}{1, 2, 3, 4, 5}
var fn govalidator.ResultIterator = func(value interface{}, index int) interface{} {
	return value.(int) * 3
}
_ = govalidator.Map(data, fn) // result = []interface{}{1, 6, 9, 12, 15}
data := []interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
var fn govalidator.ConditionIterator = func(value interface{}, index int) bool {
	return value.(int)%2 == 0
}
_ = govalidator.Filter(data, fn) // result = []interface{}{2, 4, 6, 8, 10}
_ = govalidator.Count(data, fn) // result = 5
ValidateStruct #2

If you want to validate structs, you can use tag valid for any field in your structure. All validators used with this field in one tag are separated by comma. If you want to skip validation, place - in your tag. If you need a validator that is not on the list below, you can add it like this:

govalidator.TagMap["duck"] = govalidator.Validator(func(str string) bool {
	return str == "duck"
})

For completely custom validators (interface-based), see below.

Here is a list of available validators for struct fields (validator - used function):

"email":              IsEmail,
"url":                IsURL,
"dialstring":         IsDialString,
"requrl":             IsRequestURL,
"requri":             IsRequestURI,
"alpha":              IsAlpha,
"utfletter":          IsUTFLetter,
"alphanum":           IsAlphanumeric,
"utfletternum":       IsUTFLetterNumeric,
"numeric":            IsNumeric,
"utfnumeric":         IsUTFNumeric,
"utfdigit":           IsUTFDigit,
"hexadecimal":        IsHexadecimal,
"hexcolor":           IsHexcolor,
"rgbcolor":           IsRGBcolor,
"lowercase":          IsLowerCase,
"uppercase":          IsUpperCase,
"int":                IsInt,
"float":              IsFloat,
"null":               IsNull,
"uuid":               IsUUID,
"uuidv3":             IsUUIDv3,
"uuidv4":             IsUUIDv4,
"uuidv5":             IsUUIDv5,
"creditcard":         IsCreditCard,
"isbn10":             IsISBN10,
"isbn13":             IsISBN13,
"json":               IsJSON,
"multibyte":          IsMultibyte,
"ascii":              IsASCII,
"printableascii":     IsPrintableASCII,
"fullwidth":          IsFullWidth,
"halfwidth":          IsHalfWidth,
"variablewidth":      IsVariableWidth,
"base64":             IsBase64,
"datauri":            IsDataURI,
"ip":                 IsIP,
"port":               IsPort,
"ipv4":               IsIPv4,
"ipv6":               IsIPv6,
"dns":                IsDNSName,
"host":               IsHost,
"mac":                IsMAC,
"latitude":           IsLatitude,
"longitude":          IsLongitude,
"ssn":                IsSSN,
"semver":             IsSemver,
"rfc3339":            IsRFC3339,
"rfc3339WithoutZone": IsRFC3339WithoutZone,
"ISO3166Alpha2":      IsISO3166Alpha2,
"ISO3166Alpha3":      IsISO3166Alpha3,
"ulid":               IsULID,

Validators with parameters

"range(min|max)": Range,
"length(min|max)": ByteLength,
"runelength(min|max)": RuneLength,
"stringlength(min|max)": StringLength,
"matches(pattern)": StringMatches,
"in(string1|string2|...|stringN)": IsIn,
"rsapub(keylength)" : IsRsaPub,
"minstringlength(int): MinStringLength,
"maxstringlength(int): MaxStringLength,

Validators with parameters for any type

"type(type)": IsType,

And here is small example of usage:

type Post struct {
	Title    string `valid:"alphanum,required"`
	Message  string `valid:"duck,ascii"`
	Message2 string `valid:"animal(dog)"`
	AuthorIP string `valid:"ipv4"`
	Date     string `valid:"-"`
}
post := &Post{
	Title:   "My Example Post",
	Message: "duck",
	Message2: "dog",
	AuthorIP: "123.234.54.3",
}

// Add your own struct validation tags
govalidator.TagMap["duck"] = govalidator.Validator(func(str string) bool {
	return str == "duck"
})

// Add your own struct validation tags with parameter
govalidator.ParamTagMap["animal"] = govalidator.ParamValidator(func(str string, params ...string) bool {
    species := params[0]
    return str == species
})
govalidator.ParamTagRegexMap["animal"] = regexp.MustCompile("^animal\\((\\w+)\\)$")

result, err := govalidator.ValidateStruct(post)
if err != nil {
	println("error: " + err.Error())
}
println(result)
ValidateMap #2

If you want to validate maps, you can use the map to be validated and a validation map that contain the same tags used in ValidateStruct, both maps have to be in the form map[string]interface{}

So here is small example of usage:

var mapTemplate = map[string]interface{}{
	"name":"required,alpha",
	"family":"required,alpha",
	"email":"required,email",
	"cell-phone":"numeric",
	"address":map[string]interface{}{
		"line1":"required,alphanum",
		"line2":"alphanum",
		"postal-code":"numeric",
	},
}

var inputMap = map[string]interface{}{
	"name":"Bob",
	"family":"Smith",
	"email":"[email protected]",
	"address":map[string]interface{}{
		"line1":"",
		"line2":"",
		"postal-code":"",
	},
}

result, err := govalidator.ValidateMap(inputMap, mapTemplate)
if err != nil {
	println("error: " + err.Error())
}
println(result)
WhiteList
// Remove all characters from string ignoring characters between "a" and "z"
println(govalidator.WhiteList("a3a43a5a4a3a2a23a4a5a4a3a4", "a-z") == "aaaaaaaaaaaa")
Custom validation functions

Custom validation using your own domain specific validators is also available - here's an example of how to use it:

import "github.com/asaskevich/govalidator"

type CustomByteArray [6]byte // custom types are supported and can be validated

type StructWithCustomByteArray struct {
  ID              CustomByteArray `valid:"customByteArrayValidator,customMinLengthValidator"` // multiple custom validators are possible as well and will be evaluated in sequence
  Email           string          `valid:"email"`
  CustomMinLength int             `valid:"-"`
}

govalidator.CustomTypeTagMap.Set("customByteArrayValidator", func(i interface{}, context interface{}) bool {
  switch v := context.(type) { // you can type switch on the context interface being validated
  case StructWithCustomByteArray:
    // you can check and validate against some other field in the context,
    // return early or not validate against the context at all – your choice
  case SomeOtherType:
    // ...
  default:
    // expecting some other type? Throw/panic here or continue
  }

  switch v := i.(type) { // type switch on the struct field being validated
  case CustomByteArray:
    for _, e := range v { // this validator checks that the byte array is not empty, i.e. not all zeroes
      if e != 0 {
        return true
      }
    }
  }
  return false
})
govalidator.CustomTypeTagMap.Set("customMinLengthValidator", func(i interface{}, context interface{}) bool {
  switch v := context.(type) { // this validates a field against the value in another field, i.e. dependent validation
  case StructWithCustomByteArray:
    return len(v.ID) >= v.CustomMinLength
  }
  return false
})
Loop over Error()

By default .Error() returns all errors in a single String. To access each error you can do this:

  if err != nil {
    errs := err.(govalidator.Errors).Errors()
    for _, e := range errs {
      fmt.Println(e.Error())
    }
  }
Custom error messages

Custom error messages are supported via annotations by adding the ~ separator - here's an example of how to use it:

type Ticket struct {
  Id        int64     `json:"id"`
  FirstName string    `json:"firstname" valid:"required~First name is blank"`
}

Notes

Documentation is available here: godoc.org. Full information about code coverage is also available here: govalidator on gocover.io.

Support

If you do have a contribution to the package, feel free to create a Pull Request or an Issue.

What to contribute

If you don't know what to do, there are some features and functions that need to be done

  • Refactor code
  • Edit docs and README: spellcheck, grammar and typo check
  • Create actual list of contributors and projects that currently using this package
  • Resolve issues and bugs
  • Update actual list of functions
  • Update list of validators that available for ValidateStruct and add new
  • Implement new validators: IsFQDN, IsIMEI, IsPostalCode, IsISIN, IsISRC etc
  • Implement validation by maps
  • Implement fuzzing testing
  • Implement some struct/map/array utilities
  • Implement map/array validation
  • Implement benchmarking
  • Implement batch of examples
  • Look at forks for new features and fixes

Advice

Feel free to create what you want, but keep in mind when you implement new features:

  • Code must be clear and readable, names of variables/constants clearly describes what they are doing
  • Public functions must be documented and described in source file and added to README.md to the list of available functions
  • There are must be unit-tests for any new functions and improvements

Credits

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Special thanks to contributors

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

FOSSA Status

# Functions

Abs returns absolute value of number.
BlackList removes characters that appear in the blacklist.
ByteLength checks string's length.
CamelCaseToUnderscore converts from camel case form to underscore separated form.
Contains checks if the string contains the substring.
Count iterates over the slice and apply ConditionIterator to every item.
Each iterates over the slice and apply Iterator to every item.
ErrorByField returns error for specified field of the struct validated by ValidateStruct or empty string if there are no errors or this field doesn't exists or doesn't have any errors.
ErrorsByField returns map of errors of the struct validated by ValidateStruct or empty map if there are no errors.
Every validates that every item of array corresponds to ConditionIterator.
Filter iterates over the slice and apply ConditionIterator to every item.
Find iterates over the slice and apply ConditionIterator to every item.
GetLine returns specified line of multiline string.
GetLines splits string by "\n" and return array of lines.
HasLowerCase checks if the string contains at least 1 lowercase.
HasUpperCase checks if the string contains as least 1 uppercase.
HasWhitespace checks if the string contains any whitespace.
HasWhitespaceOnly checks the string only contains whitespace.
InRange returns true if value lies between left and right border, generic type to handle int, float32, float64 and string.
InRangeFloat32 returns true if value lies between left and right border.
InRangeFloat64 returns true if value lies between left and right border.
InRangeInt returns true if value lies between left and right border.
IsAlpha checks if the string contains only letters (a-zA-Z).
IsAlphanumeric checks if the string contains only letters and numbers.
IsASCII checks if the string contains ASCII chars only.
IsBase64 checks if a string is base64 encoded.
IsByteLength checks if the string's length (in bytes) falls in a range.
IsCIDR checks if the string is an valid CIDR notiation (IPV4 & IPV6).
IsCRC32 checks is a string is a CRC32 hash.
IsCRC32b checks is a string is a CRC32b hash.
IsCreditCard checks if the string is a credit card.
IsDataURI checks if a string is base64 encoded data URI such as an image.
IsDialString validates the given string for usage with the various Dial() functions.
IsDivisibleBy checks if the string is a number that's divisible by another.
IsDNSName will validate the given string as a DNS name.
IsEmail checks if the string is an email.
IsExistingEmail checks if the string is an email of existing domain.
IsFilePath checks is a string is Win or Unix file path and returns it's type.
IsFloat checks if the string is a float.
IsFullWidth checks if the string contains any full-width chars.
IsHalfWidth checks if the string contains any half-width chars.
IsHash checks if a string is a hash of type algorithm.
IsHexadecimal checks if the string is a hexadecimal number.
IsHexcolor checks if the string is a hexadecimal color.
IsHost checks if the string is a valid IP (both v4 and v6) or a valid DNS name.
IsIMEI checks if a string is valid IMEI.
IsIMSI checks if a string is valid IMSI.
IsIn checks if string str is a member of the set of strings params.
IsInRaw checks if string is in list of allowed values.
IsInt checks if the string is an integer.
IsIP checks if a string is either IP version 4 or 6.
IsIPv4 checks if the string is an IP version 4.
IsIPv6 checks if the string is an IP version 6.
IsISBN checks if the string is an ISBN (version 10 or 13).
IsISBN10 checks if the string is an ISBN version 10.
IsISBN13 checks if the string is an ISBN version 13.
IsISO3166Alpha2 checks if a string is valid two-letter country code.
IsISO3166Alpha3 checks if a string is valid three-letter country code.
IsISO4217 checks if string is valid ISO currency code.
IsISO693Alpha2 checks if a string is valid two-letter language code.
IsISO693Alpha3b checks if a string is valid three-letter language code.
IsJSON checks if the string is valid JSON (note: uses json.Unmarshal).
IsLatitude checks if a string is valid latitude.
IsLongitude checks if a string is valid longitude.
IsLowerCase checks if the string is lowercase.
IsMAC checks if a string is valid MAC address.
IsMagnetURI checks if a string is valid magnet URI.
IsMD4 checks is a string is a MD4 hash.
IsMD5 checks is a string is a MD5 hash.
IsMongoID checks if the string is a valid hex-encoded representation of a MongoDB ObjectId.
IsMultibyte checks if the string contains one or more multibyte chars.
IsNatural returns true if value is natural number (positive and whole).
IsNegative returns true if value < 0.
IsNonNegative returns true if value >= 0.
IsNonPositive returns true if value <= 0.
IsNotNull checks if the string is not null.
IsNull checks if the string is null.
IsNumeric checks if the string contains only numbers.
IsPort checks if a string represents a valid port.
IsPositive returns true if value > 0.
IsPrintableASCII checks if the string contains printable ASCII chars only.
IsRegex checks if a give string is a valid regex with RE2 syntax or not.
IsRequestURI checks if the string rawurl, assuming it was received in an HTTP request, is an absolute URI or an absolute path.
IsRequestURL checks if the string rawurl, assuming it was received in an HTTP request, is a valid URL confirm to RFC 3986.
IsRFC3339 checks if string is valid timestamp value according to RFC3339.
IsRFC3339WithoutZone checks if string is valid timestamp value according to RFC3339 which excludes the timezone.
IsRGBcolor checks if the string is a valid RGB color in form rgb(RRR, GGG, BBB).
IsRipeMD128 checks is a string is a RipeMD128 hash.
IsRipeMD160 checks is a string is a RipeMD160 hash.
IsRsaPub checks whether string is valid RSA key Alias for IsRsaPublicKey.
IsRsaPublicKey checks if a string is valid public key with provided length.
IsSemver checks if string is valid semantic version.
IsSHA1 checks is a string is a SHA-1 hash.
IsSHA256 checks is a string is a SHA256 hash.
IsSHA3224 checks is a string is a SHA3-224 hash.
IsSHA3256 checks is a string is a SHA3-256 hash.
IsSHA3384 checks is a string is a SHA3-384 hash.
IsSHA3512 checks is a string is a SHA3-512 hash.
IsSHA384 checks is a string is a SHA384 hash.
IsSHA512 checks is a string is a SHA512 hash.
IsSSN will validate the given string as a U.S.
IsTiger128 checks is a string is a Tiger128 hash.
IsTiger160 checks is a string is a Tiger160 hash.
IsTiger192 checks is a string is a Tiger192 hash.
IsTime checks if string is valid according to given format.
IsType checks if interface is of some type.
IsULID checks if the string is a ULID.
IsUnixFilePath checks both relative & absolute paths in Unix.
IsUnixTime checks if string is valid unix timestamp value.
IsUpperCase checks if the string is uppercase.
IsURL checks if the string is an URL.
IsUTFDigit checks if the string contains only unicode radix-10 decimal digits.
IsUTFLetter checks if the string contains only unicode letter characters.Similar to IsAlpha but for all languages.
IsUTFLetterNumeric checks if the string contains only unicode letters and numbers.
IsUTFNumeric checks if the string contains only unicode numbers of any kind.
IsUUID checks if the string is a UUID (version 3, 4 or 5).
IsUUIDv3 checks if the string is a UUID version 3.
IsUUIDv4 checks if the string is a UUID version 4.
IsUUIDv5 checks if the string is a UUID version 5.
IsVariableWidth checks if the string contains a mixture of full and half-width chars.
IsWhole returns true if value is whole number.
IsWinFilePath checks both relative & absolute paths in Windows.
LeftTrim trims characters from the left side of the input.
Map iterates over the slice and apply ResultIterator to every item.
Matches checks if string matches the pattern (pattern is regular expression) In case of error return false.
MaxStringLength checks string's maximum length (including multi byte strings).
MinStringLength checks string's minimum length (including multi byte strings).
NormalizeEmail canonicalize an email address.
PadBoth pads both sides of a string if size of string is less then indicated pad length.
PadLeft pads left side of a string if size of string is less then indicated pad length.
PadRight pads right side of a string if size of string is less then indicated pad length.
Range checks string's length.
Reduce boils down a list of values into a single value by ReduceIterator.
RemoveTags removes all tags from HTML string.
ReplacePattern replaces regular expression pattern in string.
Reverse returns reversed string.
RightTrim trims characters from the right side of the input.
RuneLength checks string's length Alias for StringLength.
SafeFileName returns safe string that can be used in file names.
SetFieldsRequiredByDefault causes validation to fail when struct fields do not include validations or are not explicitly marked as exempt (using `valid:"-"` or `valid:"email,optional"`).
SetNilPtrAllowedByRequired causes validation to pass for nil ptrs when a field is set to required.
Sign returns signum of number: 1 in case of value > 0, -1 in case of value < 0, 0 otherwise.
Some validates that any item of array corresponds to ConditionIterator.
StringLength checks string's length (including multi byte strings).
StringMatches checks if a string matches a given pattern.
StripLow removes characters with a numerical value < 32 and 127, mostly control characters.
ToBoolean convert the input string to a boolean.
ToFloat convert the input string to a float, or 0.0 if the input is not a float.
ToInt convert the input string or any int type to an integer type 64, or 0 if the input is not an integer.
ToJSON convert the input to a valid JSON string.
ToString convert the input to a string.
Trim trims characters from both sides of the input.
Truncate a string to the closest length without breaking words.
TruncatingErrorf removes extra args from fmt.Errorf if not formatted in the str object.
UnderscoreToCamelCase converts from underscore separated form to camel case form.
ValidateArray performs validation according to condition iterator that validates every element of the array.
ValidateMap use validation map for fields.
ValidateMapAsync performs async validation of the map and returns results through the channels.
ValidateStruct use tags for fields.
ValidateStructAsync performs async validation of the struct and returns results through the channels.
WhiteList removes characters that do not appear in the whitelist.

# Constants

Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Unix is *nix OS types.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Unknown is unresolved OS type.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.
Win is Windows type.
Basic regular expressions for validating strings.
Basic regular expressions for validating strings.

# Variables

CustomTypeTagMap is a map of functions that can be used as tags for ValidateStruct function.
Escape replaces <, >, & and " with HTML entities.
InterfaceParamTagMap is a map of functions accept variants parameters for an interface value.
InterfaceParamTagRegexMap maps interface param tags to their respective regexes.
ISO3166List based on https://www.iso.org/obp/ui/#search/code/ Code Type "Officially Assigned Codes".
ISO4217List is the list of ISO currency codes.
ISO693List based on http://data.okfn.org/data/core/language-codes/r/language-codes-3b2.json.
ParamTagMap is a map of functions accept variants parameters.
ParamTagRegexMap maps param tags to their respective regexes.
TagMap is a map of functions, that can be used as tags for ValidateStruct function.

# Structs

Error encapsulates a name, an error and whether there's a custom error message or not.
ISO3166Entry stores country codes.
ISO693Entry stores ISO language codes.
UnsupportedTypeError is a wrapper for reflect.Type.

# Type aliases

ConditionIterator is the function that accepts element of slice/array and its index and returns boolean.
CustomTypeValidator is a wrapper for validator functions that returns bool and accepts any type.
Errors is an array of multiple errors and conforms to the error interface.
InterfaceParamValidator is a wrapper for functions that accept variants parameters for an interface value.
Iterator is the function that accepts element of slice/array and its index.
ParamValidator is a wrapper for validator functions that accept additional parameters.
ReduceIterator is the function that accepts two element of slice/array and returns result of merging those values.
ResultIterator is the function that accepts element of slice/array and its index and returns any result.
Validator is a wrapper for a validator function that returns bool and accepts string.