A package of validators and sanitizers for strings, structs and collections.
features:
- Customizable Attributes.
- Customizable error messages.
- Support i18n messages
Make sure that Go is installed on your computer. Type the following command in your terminal:
go get github.com/syssam/go-validator
- omitempty
- required
- requiredIf
- requiredUnless
- requiredWith
- requiredWithAll
- requiredWithout
- requiredWithoutAll
- between
- digitsBetween
- size
- max
- min
- same
- gt
- gte
- lt
- lte
- distinct
- alpha
- alphaNum
- alphaDash
- alphaUnicode
- alphaNumUnicode
- alphaDashUnicode
- numeric
- int
- integer
- float
- null
- ip
- ipv4
- ipv6
- uuid3
- uuid4
- uuid5
- uuid
The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string.
The field under validation must be present in the input data and not empty. A field is considered "empty" if one of the following conditions are true:
- The value is
nil. - The value is an empty string.
- The value is an empty array | map
The field under validation must be present and not empty if the anotherfield field is equal to any value.
The field under validation must be present and not empty unless the anotherfield field is equal to any value.
The field under validation must be present and not empty only if any of the other specified fields are present.
The field under validation must be present and not empty only if all of the other specified fields are present.
The field under validation must be present and not empty only when any of the other specified fields are not present.
The field under validation must be present and not empty only when all of the other specified fields are not present.
The field under validation must have a size between the given min and max. String, Number, Array, Map are evaluated in the same fashion as the size rule.
The field under validation must have a length between the given min and max.
The field under validation must have a size matching the given value. For string data, value corresponds to the number of characters. For numeric data, value corresponds to a given integer value. For an array | map | slice, size corresponds to the count of the array | map | slice.
The field under validation must be less than or equal to a maximum value. String, Number, Array, Map are evaluated in the same fashion as the size rule.
The field under validation must be greater than or equal to a minimum value. String, Number, Array, Map are evaluated in the same fashion as the size rule.
The given field must match the field under validation.
The field under validation must be greater than the given field. The two fields must be of the same type. String, Number, Array, Map are evaluated using the same conventions as the size rule.
The field under validation must be greater than or equal to the given field. The two fields must be of the same type. String, Number, Array, Map are evaluated using the same conventions as the size rule.
The field under validation must be less than the given field. The two fields must be of the same type. String, Number, Array, Map are evaluated using the same conventions as the size rule.
The field under validation must be less than or equal to the given field. The two fields must be of the same type. String, Number, Array, Map are evaluated using the same conventions as the size rule.
The field under validation must not have any duplicate values.
The field under validation must be formatted as an e-mail address.
The field under validation may be only contains letters. Empty string is valid.
The field under validation may be only contains letters and numbers. Empty string is valid.
The field under validation may be only contains letters, numbers, dashes and underscores. Empty string is valid.
The field under validation may be only contains letters. Empty string is valid.
The field under validation may be only contains letters and numbers. Empty string is valid.
The field under validation may be only contains letters, numbers, dashes and underscores. Empty string is valid.
The field under validation must be numbers. Empty string is valid.
The field under validation must be int. Empty string is valid.
The field under validation must be float. Empty string is valid.
The field under validation must be an IP address.
The field under validation must be an IPv4 address.
The field under validation must be an IPv6 address.
The field under validation must be an uuid3.
The field under validation must be an uuid4.
The field under validation must be an uuid5.
The field under validation must be an uuid.
validator.CustomTypeTagMap.Set("customValidator", func CustomValidator(v reflect.Value, o reflect.Value, validTag *validator.ValidTag) bool {
return false
})
IsNumeric(str string) bool
IsInt(str string) bool
IsFloat(str string) bool
IsNull(str string) bool
ValidateBetween(i interface{}, params []string) (bool, error)
ValidateDigitsBetween(i interface{}, params []string) (bool, error)
ValidateDigitsBetweenInt64(value, left, right int64) bool
ValidateDigitsBetweenFloat64(value, left, right float64) bool
ValidateGt(i interface{}, a interface{}) (bool, error)
ValidateGtFloat64(v, param float64) bool
ValidateGte(i interface{}, a interface{}) (bool, error)
ValidateGteFloat64(v, param float64) bool
ValidateLt(i interface{}, a interface{}) (bool, error)
ValidateLtFloat64(v, param float64) bool
ValidateLte(i interface{}, a interface{}) (bool, error)
ValidateLteFloat64(v, param float64) bool
ValidateRequired(i interface{}) bool
ValidateMin(i interface{}, params []string) (bool, error)
ValidateMinFloat64(v, param float64) bool
ValidateMax(i interface{}, params []string) (bool, error)
ValidateMaxFloat64(v, param float64) bool
ValidateSize(i interface{}, params []string) (bool, error)
ValidateDistinct(i interface{}) bool
ValidateEmail(str string) bool
ValidateAlpha(str string) bool
ValidateAlphaNum(str string) bool
ValidateAlphaDash(str string) bool
ValidateAlphaUnicode(str string) bool
ValidateAlphaNumUnicode(str string) bool
ValidateAlphaDashUnicode(str string) bool
ValidateIP(str string) bool
ValidateIPv4(str string) bool
ValidateIPv6(str string) bool
ValidateUUID3(str string) bool
ValidateUUID4(str string) bool
ValidateUUID5(str string) bool
ValidateUUID(str string) bool
ValidateURL(str string) bool