mirror of
https://github.com/Fishwaldo/validator.git
synced 2025-07-07 21:49:54 +00:00
parent
a53d64fc35
commit
d07eb88fb0
13 changed files with 203 additions and 183 deletions
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
* @go-playground/validator-maintainers
|
3
.github/ISSUE_TEMPLATE.md
vendored
3
.github/ISSUE_TEMPLATE.md
vendored
|
@ -1,3 +1,6 @@
|
||||||
|
- [ ] I have looked at the documentation [here](https://pkg.go.dev/github.com/go-playground/validator/v10#section-documentation) first?
|
||||||
|
- [ ] I have looked at the examples provided that may showcase my question [here](/_examples)?
|
||||||
|
|
||||||
### Package version eg. v9, v10:
|
### Package version eg. v9, v10:
|
||||||
|
|
||||||
|
|
||||||
|
|
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
|
@ -4,4 +4,4 @@
|
||||||
**Make sure that you've checked the boxes below before you submit PR:**
|
**Make sure that you've checked the boxes below before you submit PR:**
|
||||||
- [ ] Tests exist or have been written that cover this particular change.
|
- [ ] Tests exist or have been written that cover this particular change.
|
||||||
|
|
||||||
@go-playground/admins
|
@go-playground/validator-maintainers
|
6
.github/workflows/workflow.yml
vendored
6
.github/workflows/workflow.yml
vendored
|
@ -8,7 +8,7 @@ jobs:
|
||||||
test:
|
test:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go-version: [1.14.x, 1.15.x]
|
go-version: [1.15.x, 1.16.x]
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
|
@ -32,7 +32,7 @@ jobs:
|
||||||
run: go test -race -covermode=atomic -coverprofile="profile.cov" ./...
|
run: go test -race -covermode=atomic -coverprofile="profile.cov" ./...
|
||||||
|
|
||||||
- name: Send Coverage
|
- name: Send Coverage
|
||||||
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.15.x'
|
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.16.x'
|
||||||
uses: shogo82148/actions-goveralls@v1
|
uses: shogo82148/actions-goveralls@v1
|
||||||
with:
|
with:
|
||||||
path-to-profile: profile.cov
|
path-to-profile: profile.cov
|
||||||
|
@ -45,4 +45,4 @@ jobs:
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: golangci/golangci-lint-action@v2
|
||||||
with:
|
with:
|
||||||
version: v1.31
|
version: v1.39
|
||||||
|
|
16
MAINTAINERS.md
Normal file
16
MAINTAINERS.md
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
## Maintainers Guide
|
||||||
|
|
||||||
|
### Semantic Versioning
|
||||||
|
Semantic versioning as defined [here](https://semver.org) must be strictly adhered to.
|
||||||
|
|
||||||
|
### External Dependencies
|
||||||
|
Any new external dependencies MUST:
|
||||||
|
- Have a compatible LICENSE present.
|
||||||
|
- Be actively maintained.
|
||||||
|
- Be approved by @go-playground/admins
|
||||||
|
|
||||||
|
### PR Merge Requirements
|
||||||
|
- Up-to-date branch.
|
||||||
|
- Passing tests and linting.
|
||||||
|
- CODEOWNERS approval.
|
||||||
|
- Tests that cover both the Happy and Unhappy paths.
|
4
Makefile
4
Makefile
|
@ -3,11 +3,11 @@ GOCMD=GO111MODULE=on go
|
||||||
linters-install:
|
linters-install:
|
||||||
@golangci-lint --version >/dev/null 2>&1 || { \
|
@golangci-lint --version >/dev/null 2>&1 || { \
|
||||||
echo "installing linting tools..."; \
|
echo "installing linting tools..."; \
|
||||||
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.21.0; \
|
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.39.0; \
|
||||||
}
|
}
|
||||||
|
|
||||||
lint: linters-install
|
lint: linters-install
|
||||||
$(PWD)/bin/golangci-lint run
|
golangci-lint run
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(GOCMD) test -cover -race ./...
|
$(GOCMD) test -cover -race ./...
|
||||||
|
|
11
README.md
11
README.md
|
@ -1,7 +1,7 @@
|
||||||
Package validator
|
Package validator
|
||||||
================
|
=================
|
||||||
<img align="right" src="https://raw.githubusercontent.com/go-playground/validator/v9/logo.png">[](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
<img align="right" src="https://raw.githubusercontent.com/go-playground/validator/v9/logo.png">[](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||

|

|
||||||
[](https://travis-ci.org/go-playground/validator)
|
[](https://travis-ci.org/go-playground/validator)
|
||||||
[](https://coveralls.io/github/go-playground/validator?branch=master)
|
[](https://coveralls.io/github/go-playground/validator?branch=master)
|
||||||
[](https://goreportcard.com/report/github.com/go-playground/validator)
|
[](https://goreportcard.com/report/github.com/go-playground/validator)
|
||||||
|
@ -295,5 +295,10 @@ How to Contribute
|
||||||
Make a pull request...
|
Make a pull request...
|
||||||
|
|
||||||
License
|
License
|
||||||
------
|
-------
|
||||||
Distributed under MIT License, please see license file within the code for more details.
|
Distributed under MIT License, please see license file within the code for more details.
|
||||||
|
|
||||||
|
Maintainers
|
||||||
|
-----------
|
||||||
|
This project has grown large enough that more than one person is required to properly support the community.
|
||||||
|
If you are interested in becoming a maintainer please reach out to me https://github.com/deankarn
|
12
baked_in.go
12
baked_in.go
|
@ -552,7 +552,7 @@ func isEthereumAddress(fl FieldLevel) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if ethaddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) {
|
if ethAddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1225,8 +1225,6 @@ func isPostcodeByIso3166Alpha2(fl FieldLevel) bool {
|
||||||
// example: `postcode_iso3166_alpha2_field=CountryCode`
|
// example: `postcode_iso3166_alpha2_field=CountryCode`
|
||||||
func isPostcodeByIso3166Alpha2Field(fl FieldLevel) bool {
|
func isPostcodeByIso3166Alpha2Field(fl FieldLevel) bool {
|
||||||
field := fl.Field()
|
field := fl.Field()
|
||||||
kind := field.Kind()
|
|
||||||
|
|
||||||
params := parseOneOfParam2(fl.Param())
|
params := parseOneOfParam2(fl.Param())
|
||||||
|
|
||||||
if len(params) != 1 {
|
if len(params) != 1 {
|
||||||
|
@ -1390,7 +1388,7 @@ func isRGB(fl FieldLevel) bool {
|
||||||
|
|
||||||
// IsHEXColor is the validation function for validating if the current field's value is a valid HEX color.
|
// IsHEXColor is the validation function for validating if the current field's value is a valid HEX color.
|
||||||
func isHEXColor(fl FieldLevel) bool {
|
func isHEXColor(fl FieldLevel) bool {
|
||||||
return hexcolorRegex.MatchString(fl.Field().String())
|
return hexColorRegex.MatchString(fl.Field().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsHexadecimal is the validation function for validating if the current field's value is a valid hexadecimal.
|
// IsHexadecimal is the validation function for validating if the current field's value is a valid hexadecimal.
|
||||||
|
@ -2363,9 +2361,5 @@ func isBCP47LanguageTag(fl FieldLevel) bool {
|
||||||
func isIsoBicFormat(fl FieldLevel) bool {
|
func isIsoBicFormat(fl FieldLevel) bool {
|
||||||
bicString := fl.Field().String()
|
bicString := fl.Field().String()
|
||||||
|
|
||||||
if !bicRegex.MatchString(bicString) {
|
return bicRegex.MatchString(bicString)
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
20
errors.go
20
errors.go
|
@ -82,7 +82,7 @@ func (ve ValidationErrors) Translate(ut ut.Translator) ValidationErrorsTranslati
|
||||||
// FieldError contains all functions to get error details
|
// FieldError contains all functions to get error details
|
||||||
type FieldError interface {
|
type FieldError interface {
|
||||||
|
|
||||||
// returns the validation tag that failed. if the
|
// Tag returns the validation tag that failed. if the
|
||||||
// validation was an alias, this will return the
|
// validation was an alias, this will return the
|
||||||
// alias name and not the underlying tag that failed.
|
// alias name and not the underlying tag that failed.
|
||||||
//
|
//
|
||||||
|
@ -90,7 +90,7 @@ type FieldError interface {
|
||||||
// will return "iscolor"
|
// will return "iscolor"
|
||||||
Tag() string
|
Tag() string
|
||||||
|
|
||||||
// returns the validation tag that failed, even if an
|
// ActualTag returns the validation tag that failed, even if an
|
||||||
// alias the actual tag within the alias will be returned.
|
// alias the actual tag within the alias will be returned.
|
||||||
// If an 'or' validation fails the entire or will be returned.
|
// If an 'or' validation fails the entire or will be returned.
|
||||||
//
|
//
|
||||||
|
@ -98,7 +98,7 @@ type FieldError interface {
|
||||||
// will return "hexcolor|rgb|rgba|hsl|hsla"
|
// will return "hexcolor|rgb|rgba|hsl|hsla"
|
||||||
ActualTag() string
|
ActualTag() string
|
||||||
|
|
||||||
// returns the namespace for the field error, with the tag
|
// Namespace returns the namespace for the field error, with the tag
|
||||||
// name taking precedence over the field's actual name.
|
// name taking precedence over the field's actual name.
|
||||||
//
|
//
|
||||||
// eg. JSON name "User.fname"
|
// eg. JSON name "User.fname"
|
||||||
|
@ -109,7 +109,7 @@ type FieldError interface {
|
||||||
// using validate.Field(...) as there is no way to extract it's name
|
// using validate.Field(...) as there is no way to extract it's name
|
||||||
Namespace() string
|
Namespace() string
|
||||||
|
|
||||||
// returns the namespace for the field error, with the field's
|
// StructNamespace returns the namespace for the field error, with the field's
|
||||||
// actual name.
|
// actual name.
|
||||||
//
|
//
|
||||||
// eq. "User.FirstName" see Namespace for comparison
|
// eq. "User.FirstName" see Namespace for comparison
|
||||||
|
@ -118,24 +118,24 @@ type FieldError interface {
|
||||||
// using validate.Field(...) as there is no way to extract its name
|
// using validate.Field(...) as there is no way to extract its name
|
||||||
StructNamespace() string
|
StructNamespace() string
|
||||||
|
|
||||||
// returns the fields name with the tag name taking precedence over the
|
// Field returns the fields name with the tag name taking precedence over the
|
||||||
// field's actual name.
|
// field's actual name.
|
||||||
//
|
//
|
||||||
// eq. JSON name "fname"
|
// eq. JSON name "fname"
|
||||||
// see StructField for comparison
|
// see StructField for comparison
|
||||||
Field() string
|
Field() string
|
||||||
|
|
||||||
// returns the field's actual name from the struct, when able to determine.
|
// StructField returns the field's actual name from the struct, when able to determine.
|
||||||
//
|
//
|
||||||
// eq. "FirstName"
|
// eq. "FirstName"
|
||||||
// see Field for comparison
|
// see Field for comparison
|
||||||
StructField() string
|
StructField() string
|
||||||
|
|
||||||
// returns the actual field's value in case needed for creating the error
|
// Value returns the actual field's value in case needed for creating the error
|
||||||
// message
|
// message
|
||||||
Value() interface{}
|
Value() interface{}
|
||||||
|
|
||||||
// returns the param value, in string form for comparison; this will also
|
// Param returns the param value, in string form for comparison; this will also
|
||||||
// help with generating an error message
|
// help with generating an error message
|
||||||
Param() string
|
Param() string
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ type FieldError interface {
|
||||||
// eg. time.Time's type is time.Time
|
// eg. time.Time's type is time.Time
|
||||||
Type() reflect.Type
|
Type() reflect.Type
|
||||||
|
|
||||||
// returns the FieldError's translated error
|
// Translate returns the FieldError's translated error
|
||||||
// from the provided 'ut.Translator' and registered 'TranslationFunc'
|
// from the provided 'ut.Translator' and registered 'TranslationFunc'
|
||||||
//
|
//
|
||||||
// NOTE: if no registered translator can be found it returns the same as
|
// NOTE: if no registered translator can be found it returns the same as
|
||||||
|
@ -221,7 +221,7 @@ func (fe *fieldError) Field() string {
|
||||||
// return fld
|
// return fld
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the field's actual name from the struct, when able to determine.
|
// StructField returns the field's actual name from the struct, when able to determine.
|
||||||
func (fe *fieldError) StructField() string {
|
func (fe *fieldError) StructField() string {
|
||||||
// return fe.structField
|
// return fe.structField
|
||||||
return fe.structNs[len(fe.structNs)-int(fe.structfieldLen):]
|
return fe.structNs[len(fe.structNs)-int(fe.structfieldLen):]
|
||||||
|
|
|
@ -5,24 +5,25 @@ import "reflect"
|
||||||
// FieldLevel contains all the information and helper functions
|
// FieldLevel contains all the information and helper functions
|
||||||
// to validate a field
|
// to validate a field
|
||||||
type FieldLevel interface {
|
type FieldLevel interface {
|
||||||
// returns the top level struct, if any
|
|
||||||
|
// Top returns the top level struct, if any
|
||||||
Top() reflect.Value
|
Top() reflect.Value
|
||||||
|
|
||||||
// returns the current fields parent struct, if any or
|
// Parent returns the current fields parent struct, if any or
|
||||||
// the comparison value if called 'VarWithValue'
|
// the comparison value if called 'VarWithValue'
|
||||||
Parent() reflect.Value
|
Parent() reflect.Value
|
||||||
|
|
||||||
// returns current field for validation
|
// Field returns current field for validation
|
||||||
Field() reflect.Value
|
Field() reflect.Value
|
||||||
|
|
||||||
// returns the field's name with the tag
|
// FieldName returns the field's name with the tag
|
||||||
// name taking precedence over the fields actual name.
|
// name taking precedence over the fields actual name.
|
||||||
FieldName() string
|
FieldName() string
|
||||||
|
|
||||||
// returns the struct field's name
|
// StructFieldName returns the struct field's name
|
||||||
StructFieldName() string
|
StructFieldName() string
|
||||||
|
|
||||||
// returns param for validation against current field
|
// Param returns param for validation against current field
|
||||||
Param() string
|
Param() string
|
||||||
|
|
||||||
// GetTag returns the current validations tag name
|
// GetTag returns the current validations tag name
|
||||||
|
@ -33,7 +34,7 @@ type FieldLevel interface {
|
||||||
// underlying value and it's kind.
|
// underlying value and it's kind.
|
||||||
ExtractType(field reflect.Value) (value reflect.Value, kind reflect.Kind, nullable bool)
|
ExtractType(field reflect.Value) (value reflect.Value, kind reflect.Kind, nullable bool)
|
||||||
|
|
||||||
// traverses the parent struct to retrieve a specific field denoted by the provided namespace
|
// GetStructFieldOK traverses the parent struct to retrieve a specific field denoted by the provided namespace
|
||||||
// in the param and returns the field, field kind and whether is was successful in retrieving
|
// in the param and returns the field, field kind and whether is was successful in retrieving
|
||||||
// the field at all.
|
// the field at all.
|
||||||
//
|
//
|
||||||
|
@ -49,7 +50,7 @@ type FieldLevel interface {
|
||||||
// Deprecated: Use GetStructFieldOKAdvanced2() instead which also return if the value is nullable.
|
// Deprecated: Use GetStructFieldOKAdvanced2() instead which also return if the value is nullable.
|
||||||
GetStructFieldOKAdvanced(val reflect.Value, namespace string) (reflect.Value, reflect.Kind, bool)
|
GetStructFieldOKAdvanced(val reflect.Value, namespace string) (reflect.Value, reflect.Kind, bool)
|
||||||
|
|
||||||
// traverses the parent struct to retrieve a specific field denoted by the provided namespace
|
// GetStructFieldOK2 traverses the parent struct to retrieve a specific field denoted by the provided namespace
|
||||||
// in the param and returns the field, field kind, if it's a nullable type and whether is was successful in retrieving
|
// in the param and returns the field, field kind, if it's a nullable type and whether is was successful in retrieving
|
||||||
// the field at all.
|
// the field at all.
|
||||||
//
|
//
|
||||||
|
@ -57,7 +58,7 @@ type FieldLevel interface {
|
||||||
// could not be retrieved because it didn't exist.
|
// could not be retrieved because it didn't exist.
|
||||||
GetStructFieldOK2() (reflect.Value, reflect.Kind, bool, bool)
|
GetStructFieldOK2() (reflect.Value, reflect.Kind, bool, bool)
|
||||||
|
|
||||||
// GetStructFieldOKAdvanced is the same as GetStructFieldOK except that it accepts the parent struct to start looking for
|
// GetStructFieldOKAdvanced2 is the same as GetStructFieldOK except that it accepts the parent struct to start looking for
|
||||||
// the field and namespace allowing more extensibility for validators.
|
// the field and namespace allowing more extensibility for validators.
|
||||||
GetStructFieldOKAdvanced2(val reflect.Value, namespace string) (reflect.Value, reflect.Kind, bool, bool)
|
GetStructFieldOKAdvanced2(val reflect.Value, namespace string) (reflect.Value, reflect.Kind, bool, bool)
|
||||||
}
|
}
|
||||||
|
@ -107,12 +108,12 @@ func (v *validate) GetStructFieldOKAdvanced(val reflect.Value, namespace string)
|
||||||
return current, kind, found
|
return current, kind, found
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStructFieldOK returns Param returns param for validation against current field
|
// GetStructFieldOK2 returns Param returns param for validation against current field
|
||||||
func (v *validate) GetStructFieldOK2() (reflect.Value, reflect.Kind, bool, bool) {
|
func (v *validate) GetStructFieldOK2() (reflect.Value, reflect.Kind, bool, bool) {
|
||||||
return v.getStructFieldOKInternal(v.slflParent, v.ct.param)
|
return v.getStructFieldOKInternal(v.slflParent, v.ct.param)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStructFieldOKAdvanced is the same as GetStructFieldOK except that it accepts the parent struct to start looking for
|
// GetStructFieldOKAdvanced2 is the same as GetStructFieldOK except that it accepts the parent struct to start looking for
|
||||||
// the field and namespace allowing more extensibility for validators.
|
// the field and namespace allowing more extensibility for validators.
|
||||||
func (v *validate) GetStructFieldOKAdvanced2(val reflect.Value, namespace string) (reflect.Value, reflect.Kind, bool, bool) {
|
func (v *validate) GetStructFieldOKAdvanced2(val reflect.Value, namespace string) (reflect.Value, reflect.Kind, bool, bool) {
|
||||||
return v.getStructFieldOKInternal(val, namespace)
|
return v.getStructFieldOKInternal(val, namespace)
|
||||||
|
|
|
@ -10,7 +10,7 @@ const (
|
||||||
numericRegexString = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
|
numericRegexString = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
|
||||||
numberRegexString = "^[0-9]+$"
|
numberRegexString = "^[0-9]+$"
|
||||||
hexadecimalRegexString = "^(0[xX])?[0-9a-fA-F]+$"
|
hexadecimalRegexString = "^(0[xX])?[0-9a-fA-F]+$"
|
||||||
hexcolorRegexString = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
|
hexColorRegexString = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
|
||||||
rgbRegexString = "^rgb\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*\\)$"
|
rgbRegexString = "^rgb\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*\\)$"
|
||||||
rgbaRegexString = "^rgba\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"
|
rgbaRegexString = "^rgba\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"
|
||||||
hslRegexString = "^hsl\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*\\)$"
|
hslRegexString = "^hsl\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*\\)$"
|
||||||
|
@ -60,7 +60,7 @@ var (
|
||||||
numericRegex = regexp.MustCompile(numericRegexString)
|
numericRegex = regexp.MustCompile(numericRegexString)
|
||||||
numberRegex = regexp.MustCompile(numberRegexString)
|
numberRegex = regexp.MustCompile(numberRegexString)
|
||||||
hexadecimalRegex = regexp.MustCompile(hexadecimalRegexString)
|
hexadecimalRegex = regexp.MustCompile(hexadecimalRegexString)
|
||||||
hexcolorRegex = regexp.MustCompile(hexcolorRegexString)
|
hexColorRegex = regexp.MustCompile(hexColorRegexString)
|
||||||
rgbRegex = regexp.MustCompile(rgbRegexString)
|
rgbRegex = regexp.MustCompile(rgbRegexString)
|
||||||
rgbaRegex = regexp.MustCompile(rgbaRegexString)
|
rgbaRegex = regexp.MustCompile(rgbaRegexString)
|
||||||
hslRegex = regexp.MustCompile(hslRegexString)
|
hslRegex = regexp.MustCompile(hslRegexString)
|
||||||
|
@ -93,7 +93,7 @@ var (
|
||||||
btcUpperAddressRegexBech32 = regexp.MustCompile(btcAddressUpperRegexStringBech32)
|
btcUpperAddressRegexBech32 = regexp.MustCompile(btcAddressUpperRegexStringBech32)
|
||||||
btcLowerAddressRegexBech32 = regexp.MustCompile(btcAddressLowerRegexStringBech32)
|
btcLowerAddressRegexBech32 = regexp.MustCompile(btcAddressLowerRegexStringBech32)
|
||||||
ethAddressRegex = regexp.MustCompile(ethAddressRegexString)
|
ethAddressRegex = regexp.MustCompile(ethAddressRegexString)
|
||||||
ethaddressRegexUpper = regexp.MustCompile(ethAddressUpperRegexString)
|
ethAddressRegexUpper = regexp.MustCompile(ethAddressUpperRegexString)
|
||||||
ethAddressRegexLower = regexp.MustCompile(ethAddressLowerRegexString)
|
ethAddressRegexLower = regexp.MustCompile(ethAddressLowerRegexString)
|
||||||
uRLEncodedRegex = regexp.MustCompile(uRLEncodedRegexString)
|
uRLEncodedRegex = regexp.MustCompile(uRLEncodedRegexString)
|
||||||
hTMLEncodedRegex = regexp.MustCompile(hTMLEncodedRegexString)
|
hTMLEncodedRegex = regexp.MustCompile(hTMLEncodedRegexString)
|
||||||
|
|
|
@ -23,18 +23,18 @@ func wrapStructLevelFunc(fn StructLevelFunc) StructLevelFuncCtx {
|
||||||
// to validate a struct
|
// to validate a struct
|
||||||
type StructLevel interface {
|
type StructLevel interface {
|
||||||
|
|
||||||
// returns the main validation object, in case one wants to call validations internally.
|
// Validator returns the main validation object, in case one wants to call validations internally.
|
||||||
// this is so you don't have to use anonymous functions to get access to the validate
|
// this is so you don't have to use anonymous functions to get access to the validate
|
||||||
// instance.
|
// instance.
|
||||||
Validator() *Validate
|
Validator() *Validate
|
||||||
|
|
||||||
// returns the top level struct, if any
|
// Top returns the top level struct, if any
|
||||||
Top() reflect.Value
|
Top() reflect.Value
|
||||||
|
|
||||||
// returns the current fields parent struct, if any
|
// Parent returns the current fields parent struct, if any
|
||||||
Parent() reflect.Value
|
Parent() reflect.Value
|
||||||
|
|
||||||
// returns the current struct.
|
// Current returns the current struct.
|
||||||
Current() reflect.Value
|
Current() reflect.Value
|
||||||
|
|
||||||
// ExtractType gets the actual underlying type of field value.
|
// ExtractType gets the actual underlying type of field value.
|
||||||
|
@ -42,7 +42,7 @@ type StructLevel interface {
|
||||||
// underlying value and its kind.
|
// underlying value and its kind.
|
||||||
ExtractType(field reflect.Value) (value reflect.Value, kind reflect.Kind, nullable bool)
|
ExtractType(field reflect.Value) (value reflect.Value, kind reflect.Kind, nullable bool)
|
||||||
|
|
||||||
// reports an error just by passing the field and tag information
|
// ReportError reports an error just by passing the field and tag information
|
||||||
//
|
//
|
||||||
// NOTES:
|
// NOTES:
|
||||||
//
|
//
|
||||||
|
@ -54,7 +54,7 @@ type StructLevel interface {
|
||||||
// and process on the flip side it's up to you.
|
// and process on the flip side it's up to you.
|
||||||
ReportError(field interface{}, fieldName, structFieldName string, tag, param string)
|
ReportError(field interface{}, fieldName, structFieldName string, tag, param string)
|
||||||
|
|
||||||
// reports an error just by passing ValidationErrors
|
// ReportValidationErrors reports an error just by passing ValidationErrors
|
||||||
//
|
//
|
||||||
// NOTES:
|
// NOTES:
|
||||||
//
|
//
|
||||||
|
|
|
@ -11272,7 +11272,7 @@ func TestPostCodeByIso3166Alpha2(t *testing.T) {
|
||||||
CountryCode interface{}
|
CountryCode interface{}
|
||||||
expected bool
|
expected bool
|
||||||
}
|
}
|
||||||
defer func() { recover() }()
|
defer func() { _ = recover() }()
|
||||||
|
|
||||||
_ = New().Struct(test{"ABC", 123, false})
|
_ = New().Struct(test{"ABC", 123, false})
|
||||||
t.Errorf("Didn't panic as expected")
|
t.Errorf("Didn't panic as expected")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue