{"id":13668514,"url":"https://github.com/gookit/validate","last_synced_at":"2025-05-14T01:05:00.896Z","repository":{"id":37300104,"uuid":"141109175","full_name":"gookit/validate","owner":"gookit","description":"⚔ Go package for data validation and filtering. support Map, Struct, Form data. Go通用的数据验证与过滤库，使用简单，内置大部分常用验证、过滤器，支持自定义验证器、自定义消息、字段翻译。","archived":false,"fork":false,"pushed_at":"2025-03-31T01:31:30.000Z","size":798,"stargazers_count":1088,"open_issues_count":25,"forks_count":116,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-03T06:48:21.767Z","etag":null,"topics":["filter","govalidator","validate","validation","validator","verification"],"latest_commit_sha":null,"homepage":"https://gookit.github.io/validate/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gookit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-16T08:23:49.000Z","updated_at":"2025-03-31T01:31:34.000Z","dependencies_parsed_at":"2023-12-22T21:03:30.012Z","dependency_job_id":"97f84551-403f-4ac4-9e20-5377c3d07c6b","html_url":"https://github.com/gookit/validate","commit_stats":{"total_commits":401,"total_committers":23,"mean_commits":"17.434782608695652","dds":0.3216957605985037,"last_synced_commit":"ced40351d38b071dcaea10e4f5a4976afbc5e663"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fvalidate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fvalidate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fvalidate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fvalidate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gookit","download_url":"https://codeload.github.com/gookit/validate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248208692,"owners_count":21065205,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filter","govalidator","validate","validation","validator","verification"],"created_at":"2024-08-02T08:00:39.353Z","updated_at":"2025-04-10T11:34:36.029Z","avatar_url":"https://github.com/gookit.png","language":"Go","readme":"# Validate\n\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/validate)](https://github.com/gookit/validate)\n[![GoDoc](https://godoc.org/github.com/gookit/validate?status.svg)](https://pkg.go.dev/github.com/gookit/validate)\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gookit/goutil?style=flat-square)\n[![Coverage Status](https://coveralls.io/repos/github/gookit/validate/badge.svg?branch=master)](https://coveralls.io/github/gookit/validate?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/validate)](https://goreportcard.com/report/github.com/gookit/validate)\n[![Actions Status](https://github.com/gookit/validate/workflows/Unit-Tests/badge.svg)](https://github.com/gookit/validate/actions)\n\n`validate` is a generic Go data validate and filter tool library.\n\n- Support quick validate `Map`, `Struct`, `Request`(`Form`, `JSON`, `url.Values`, `UploadedFile`) data\n  - Validating `http.Request` automatically collects data based on the request `Content-Type` value\n  - Supports checking each child value in a slice. eg: `v.StringRule(\"tags.*\", \"required|string\")`\n- Support filter/sanitize/convert data before validate\n- Support add custom filter/validator func\n- Support scene settings, verify different fields in different scenes\n- Support custom error messages, field translates.\n  - Can use `message`, `label` tags in struct\n- Customizable i18n aware error messages, built in `en`, `zh-CN`, `zh-TW`\n- Built-in common data type filter/converter. see [Built In Filters](#built-in-filters)\n- Many commonly used validators have been built in(**\u003e 70**), see [Built In Validators](#built-in-validators)\n- Can use `validate` in any frameworks, such as Gin, Echo, Chi and more\n- Supports direct use of rules to validate value. eg: `validate.Val(\"xyz@mail.com\", \"required|email\")`\n\n## [中文说明](README.zh-CN.md)\n\n中文说明请查看 **[README.zh-CN](README.zh-CN.md)**\n\n## Go Doc\n\n- [godoc for gopkg](https://pkg.go.dev/gopkg.in/gookit/validate.v1)\n- [godoc for github](https://pkg.go.dev/github.com/gookit/validate)\n\n## Validate Struct\n\nUse the `validate` tag of the structure, you can quickly config a structure.\n\n### Config the struct use tags\n\nField translations and error messages for structs can be quickly configured using the `message` and `label` tags.\n\n- Support configuration field mapping through structure tag, read the value of `json` tag by default\n- Support configuration error message via structure's `message` tag\n- Support configuration field translation via structure's `label` tag\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/gookit/validate\"\n)\n\n// UserForm struct\ntype UserForm struct {\n\tName     string    `validate:\"required|min_len:7\" message:\"required:{field} is required\" label:\"User Name\"`\n\tEmail    string    `validate:\"email\" message:\"email is invalid\" label:\"User Email\"`\n\tAge      int       `validate:\"required|int|min:1|max:99\" message:\"int:age must int|min:age min value is 1\"`\n\tCreateAt int       `validate:\"min:1\"`\n\tSafe     int       `validate:\"-\"`\n\tUpdateAt time.Time `validate:\"required\" message:\"update time is required\"`\n\tCode     string    `validate:\"customValidator\"`\n\t// ExtInfo nested struct\n\tExtInfo struct{\n\t\tHomepage string `validate:\"required\" label:\"Home Page\"`\n\t\tCityName string\n\t} `validate:\"required\" label:\"Home Page\"`\n}\n\n// CustomValidator custom validator in the source struct.\nfunc (f UserForm) CustomValidator(val string) bool {\n\treturn len(val) == 4\n}\n```\n\n### Config validate use struct methods\n\n`validate` provides extended functionality:\n\nThe struct can implement three interfaces methods, which is convenient to do some customization:\n\n- `ConfigValidation(v *Validation)` will be called after the validator instance is created\n- `Messages() map[string]string` can customize the validator error message\n- `Translates() map[string]string` can customize field translation\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/gookit/validate\"\n)\n\n// UserForm struct\ntype UserForm struct {\n\tName     string    `validate:\"required|min_len:7\"`\n\tEmail    string    `validate:\"email\"`\n\tAge      int       `validate:\"required|int|min:1|max:99\"`\n\tCreateAt int       `validate:\"min:1\"`\n\tSafe     int       `validate:\"-\"`\n\tUpdateAt time.Time `validate:\"required\"`\n\tCode     string    `validate:\"customValidator\"`\n\t// ExtInfo nested struct\n\tExtInfo struct{\n\t\tHomepage string `validate:\"required\"`\n\t\tCityName string\n\t} `validate:\"required\"`\n}\n\n// CustomValidator custom validator in the source struct.\nfunc (f UserForm) CustomValidator(val string) bool {\n\treturn len(val) == 4\n}\n\n// ConfigValidation config the Validation\n// eg:\n// - define validate scenes\nfunc (f UserForm) ConfigValidation(v *validate.Validation) {\n\tv.WithScenes(validate.SValues{\n\t\t\"add\":    []string{\"ExtInfo.Homepage\", \"Name\", \"Code\"},\n\t\t\"update\": []string{\"ExtInfo.CityName\", \"Name\"},\n\t})\n}\n\n// Messages you can custom validator error messages. \nfunc (f UserForm) Messages() map[string]string {\n\treturn validate.MS{\n\t\t\"required\": \"oh! the {field} is required\",\n\t\t\"email\": \"email is invalid\",\n\t\t\"Name.required\": \"message for special field\",\n\t\t\"Age.int\": \"age must int\",\n\t\t\"Age.min\": \"age min value is 1\",\n\t}\n}\n\n// Translates you can custom field translates. \nfunc (f UserForm) Translates() map[string]string {\n\treturn validate.MS{\n\t\t\"Name\": \"User Name\",\n\t\t\"Email\": \"User Email\",\n\t\t\"ExtInfo.Homepage\": \"Home Page\",\n\t}\n}\n```\n\n### Create and validating\n\nCan use `validate.Struct(ptr)` quick create a validation instance. then call `v.Validate()` for validating.\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n\n  \"github.com/gookit/validate\"\n)\n\nfunc main() {\n\tu := \u0026UserForm{\n\t\tName: \"inhere\",\n\t}\n\t\n\tv := validate.Struct(u)\n\t// v := validate.New(u)\n\n\tif v.Validate() { // validate ok\n\t\t// do something ...\n\t} else {\n\t\tfmt.Println(v.Errors) // all error messages\n\t\tfmt.Println(v.Errors.One()) // returns a random error message text\n\t\tfmt.Println(v.Errors.OneError()) // returns a random error\n\t\tfmt.Println(v.Errors.Field(\"Name\")) // returns error messages of the field \n\t}\n}\n```\n\n## Validate Map\n\nYou can also validate a MAP data directly.\n\n```go\npackage main\n\nimport (\n\"fmt\"\n\n\"github.com/gookit/validate\"\n)\n\nfunc main()  {\n\tm := map[string]any{\n\t\t\"name\":  \"inhere\",\n\t\t\"age\":   100,\n\t\t\"oldSt\": 1,\n\t\t\"newSt\": 2,\n\t\t\"email\": \"some@email.com\",\n\t\t\"tags\": []string{\"go\", \"php\", \"java\"},\n\t}\n\n\tv := validate.Map(m)\n\t// v := validate.New(m)\n\tv.AddRule(\"name\", \"required\")\n\tv.AddRule(\"name\", \"minLen\", 7)\n\tv.AddRule(\"age\", \"max\", 99)\n\tv.AddRule(\"age\", \"min\", 1)\n\tv.AddRule(\"email\", \"email\")\n\t\n\t// can also\n\tv.StringRule(\"age\", \"required|int|min:1|max:99\")\n\tv.StringRule(\"name\", \"required|minLen:7\")\n\tv.StringRule(\"tags\", \"required|slice|minlen:1\")\n\t// feat: support check sub-item in slice\n\tv.StringRule(\"tags.*\", \"required|string|min_len:7\")\n\n\t// v.WithScenes(map[string]string{\n\t//\t \"create\": []string{\"name\", \"email\"},\n\t//\t \"update\": []string{\"name\"},\n\t// })\n\t\n\tif v.Validate() { // validate ok\n\t\tsafeData := v.SafeData()\n\t\t// do something ...\n\t} else {\n\t\tfmt.Println(v.Errors) // all error messages\n\t\tfmt.Println(v.Errors.One()) // returns a random error message text\n\t}\n}\n```\n\n## Validate Request\n\nIf it is an HTTP request, you can quickly validate the data and pass the verification.\nThen bind the secure data to the structure.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/gookit/validate\"\n)\n\n// UserForm struct\ntype UserForm struct {\n\tName     string\n\tEmail    string\n\tAge      int\n\tCreateAt int\n\tSafe     int\n\tUpdateAt time.Time\n\tCode     string\n}\n\nfunc main()  {\n\thandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\tdata, err := validate.FromRequest(r)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\tv := data.Create()\n\t\t// setting rules\n\t\tv.FilterRule(\"age\", \"int\") // convert value to int\n\t\t\n\t\tv.AddRule(\"name\", \"required\")\n\t\tv.AddRule(\"name\", \"minLen\", 7)\n\t\tv.AddRule(\"age\", \"max\", 99)\n\t\tv.StringRule(\"code\", `required|regex:\\d{4,6}`)\n\n\t\tif v.Validate() { // validate ok\n\t\t\t// safeData := v.SafeData()\n\t\t\tuserForm := \u0026UserForm{}\n\t\t\tv.BindSafeData(userForm)\n\n\t\t\t// do something ...\n\t\t\tfmt.Println(userForm.Name)\n\t\t} else {\n\t\t\tfmt.Println(v.Errors) // all error messages\n\t\t\tfmt.Println(v.Errors.One()) // returns a random error message text\n\t\t}\n\t})\n\n\thttp.ListenAndServe(\":8090\", handler)\n}\n```\n\n## Quick Method\n\nQuick create `Validation` instance.\n\n- `New(data any, scene ...string) *Validation`\n- `Request(r *http.Request) *Validation`\n- `JSON(s string, scene ...string) *Validation`\n- `Struct(s any, scene ...string) *Validation`\n- `Map(m map[string]any, scene ...string) *Validation`\n\nQuick create `DataFace` instance.\n\n- `FromMap(m map[string]any) *MapData`\n- `FromStruct(s any) (*StructData, error)`\n- `FromJSON(s string) (*MapData, error)`\n- `FromJSONBytes(bs []byte) (*MapData, error)`\n- `FromURLValues(values url.Values) *FormData`\n- `FromRequest(r *http.Request, maxMemoryLimit ...int64) (DataFace, error)`\n\n\u003e Create `Validation` from `DataFace`\n\n```go\nd := FromMap(map[string]any{\"key\": \"val\"})\nv := d.Validation()\n```\n\n### Methods In Validation\n\n- `func (v *Validation) Validate(scene ...string) bool` Do validating and return is success.\n- `func (v *Validation) ValidateE(scene ...string) Errors` Do validating and return error.\n\n## More Usage\n\n### Validate Error\n\n`v.Errors` is map data, top key is field name, value is `map[string]string`.\n\n```go\n// do validating\nif v.Validate() {\n\treturn nil\n}\n\n// get errors\nes := v.Errors\n\n// check\nes.Empty() // bool\n\n// returns an random error, if no error returns nil\nfmt.Println(v.Errors.OneError())\nfmt.Println(v.Errors.ErrOrNil())\n\nfmt.Println(v.Errors) // all error messages\nfmt.Println(v.Errors.One()) // returns a random error message text\nfmt.Println(v.Errors.Field(\"Name\")) // returns error messages of the field \n```\n\n**Encode to JSON**:\n\n- `StopOnError=true`(default), will only one error\n\n```json\n{\n    \"field1\": {\n        \"required\": \"error msg0\"\n    }\n}\n```\n\n- if `StopOnError=false`, will get multi error\n\n```json\n{\n    \"field1\": {\n        \"minLen\": \"error msg1\",\n        \"required\": \"error msg0\"\n    },\n    \"field2\": {\n        \"min\": \"error msg2\"\n    }\n}\n```\n\n### Global Option\n\nYou can adjust some processing logic of the validator by changing the global option settings.\n\n```go\n// GlobalOption settings for validate\ntype GlobalOption struct {\n\t// FilterTag name in the struct tags.\n\t//\n\t// default: filter\n\tFilterTag string\n\t// ValidateTag in the struct tags.\n\t//\n\t// default: validate\n\tValidateTag string\n\t// FieldTag the output field name in the struct tags.\n\t// it as placeholder on error message.\n\t//\n\t// default: json\n\tFieldTag string\n\t// LabelTag the display name in the struct tags.\n\t// use for define field translate name on error.\n\t//\n\t// default: label\n\tLabelTag string\n\t// MessageTag define error message for the field.\n\t//\n\t// default: message\n\tMessageTag string\n\t// StopOnError If true: An error occurs, it will cease to continue to verify\n\tStopOnError bool\n\t// SkipOnEmpty Skip check on field not exist or value is empty\n\tSkipOnEmpty bool\n\t// UpdateSource Whether to update source field value, useful for struct validate\n\tUpdateSource bool\n\t// CheckDefault Whether to validate the default value set by the user\n\tCheckDefault bool\n\t// CheckZero Whether validate the default zero value. (intX,uintX: 0, string: \"\")\n\tCheckZero bool\n\t// CheckSubOnParentMarked True: only collect sub-struct rule on current field has rule.\n\tCheckSubOnParentMarked bool\n\t// ValidatePrivateFields Whether to validate private fields or not, especially when inheriting other other structs.\n\t//\n\t//  type foo struct {\n\t//\t  Field int `json:\"field\" validate:\"required\"`\n\t//  }\n\t//  type bar struct {\n\t//    foo // \u003c-- validate this field\n\t//    Field2 int `json:\"field2\" validate:\"required\"`\n\t//  }\n\t//\n\t// default: false\n\tValidatePrivateFields bool\n}\n```\n\n**Usage**:\n\n```go\n// change global opts\nvalidate.Config(func(opt *validate.GlobalOption) {\n\topt.StopOnError = false\n\topt.SkipOnEmpty = false\n})\n```\n\n### Validating Private (Unexported fields)\nBy default, private fields are skipped. It is not uncommon to find code such as the following\n\n```go\ntype foo struct {\n\tsomefield int\n}\n\ntype Bar struct {\n\tfoo\n\tSomeOtherField string\n}\n```\nIn order to have `foo.somefield` validated, enable the behavior by setting `GlobalOption.ValidatePrivateFields` to `true`.\n\n```go\nvalidate.Config(func(opt *validate.GlobalOption) {\n\topt.ValidatePrivateFields = true\n})\n\n```\n\n### Custom Error Messages\n\n- Register language messages\n\n```go\nimport \"github.com/gookit/validate/locales/zhcn\"\n\n// for all Validation.\n// NOTICE: must be registered before on validate.New(), it only need call at once.\nzhcn.RegisterGlobal()\n\n// ... ...\n\nv := validate.New()\n\n// only for current Validation\nzhcn.Register(v)\n```\n\n- Manual add global messages\n\n```go\nvalidate.AddGlobalMessages(map[string]string{\n    \"minLength\": \"OO! {field} min length is %d\",\n})\n```\n\n- Add messages for current validation\n\n```go\nv := validate.New(map[string]any{\n    \"name\": \"inhere\",\n})\nv.StringRule(\"name\", \"required|string|minLen:7|maxLen:15\")\n\nv.AddMessages(map[string]string{\n    \"minLength\": \"OO! {field} min length is %d\",\n    \"name.minLen\": \"OO! username min length is %d\",\n})\n```\n\n- Use struct tags: `message, label`\n\n```go\ntype UserForm struct {\n    Name  string `validate:\"required|minLen:7\" label:\"User Name\"`\n    Email string `validate:\"email\" message:\"email is invalid\" label:\"User Email\"`\n}\n```\n\n- Use struct method `Messages()`\n\n```go\n// Messages you can custom validator error messages. \nfunc (f UserForm) Messages() map[string]string {\n\treturn validate.MS{\n\t\t\"required\": \"oh! the {field} is required\",\n\t\t\"Name.required\": \"message for special field\",\n\t}\n}\n```\n\n### Add Custom Validator\n\n`validate` supports adding custom validators, and supports adding `global validator` and `temporary validator`.\n\n- **Global Validator** is globally valid and can be used everywhere\n- **Temporary Validator** added to the current validation instance, only the current validation is available\n- Add verification method to the structure. How to use please see the structure verification example above\n\n\u003e Note: The validator method must return a `bool` to indicate whether the validation was successful.\n\u003e The first parameter is the corresponding field value. If there are additional parameters, they will be appended automatically.\n\n#### Add Global Validator\n\nYou can add one or more custom validators at once.\n\n```go\nvalidate.AddValidator(\"myCheck0\", func(val any) bool {\n\t// do validate val ...\n\treturn true\n})\nvalidate.AddValidators(validate.M{\n\t\"myCheck1\": func(val any) bool {\n\t\t// do validate val ...\n\t\treturn true\n\t},\n})\n```\n\n#### Add Temporary Validator\n\nAgain, you can add one or more custom validators at once.\n\n```go\nv := validate.Struct(u)\nv.AddValidator(\"myFunc3\", func(val any) bool {\n\t// do validate val ...\n\treturn true\n})\nv.AddValidators(validate.M{\n\t\"myFunc4\": func(val any) bool {\n\t\t// do validate val ...\n\t\treturn true\n\t},\n})\n```\n\n### Add Custom Filter\n\n`validate` can also support adding custom filters, and supports adding `global filter` and `temporary filter`.\n\n- **Global Filter** is globally valid and can be used everywhere\n- **Temporary Filter** added to the current validation instance, only the current validation is available\n\n\u003e TIP: for filter func, we allow functions with 1 result or 2 results where the second is an error.\n\n#### Add Global Filter\n\nYou can add one or more custom validators at once.\n\n```go\npackage main\n\nimport \"github.com/gookit/validate\"\n\nfunc init() {\n\tvalidate.AddFilter(\"myToIntFilter0\", func(val any) int {\n\t\t// do filtering val ...\n\t\treturn 1\n\t})\n\tvalidate.AddFilters(validate.M{\n\t\t\"myToIntFilter1\": func(val any) (int, error) {\n\t\t\t// do filtering val ...\n\t\t\treturn 1, nil\n\t\t},\n\t})\n}\n```\n\n#### Add Temporary Filter\n\nAgain, you can add one or more custom filters at once.\n\n```go\npackage main\n\nimport \"github.com/gookit/validate\"\n\nfunc main() {\n\tv := validate.New(\u0026someStrcut{})\n\n\tv.AddFilter(\"myToIntFilter0\", func(val any) int {\n\t\t// do filtering val ...\n\t\treturn 1\n\t})\n\tv.AddFilters(validate.M{\n\t\t\"myToIntFilter1\": func(val any) (int, error) {\n\t\t\t// do filtering val ...\n\t\t\treturn 1, nil\n\t\t},\n\t})\n\t// use the added filter\n\tv.FilterRule(\"field\", \"myToIntFilter0\")\n}\n```\n\n### Custom `required` validation\n\nAllows a custom `required` validator to customize whether the validation is empty.\nHowever, note that the validator name must start with `required`, e.g. `required_custom`.\n\n```go\n\ttype Data struct {\n\t\tAge  int    `validate:\"required_custom\" message:\"age is required\"`\n\t\tName string `validate:\"required\"`\n\t}\n\n\tv := validate.New(\u0026Data{\n\t\tName: \"tom\",\n\t\tAge:  0,\n\t})\n\n\tv.AddValidator(\"required_custom\", func(val any) bool {\n\t\t// do check value\n\t\treturn false\n\t})\n\n\tok := v.Validate()\n\tassert.False(t, ok)\n```\n\n## Use on gin framework\n\nCan use `validate` in any frameworks, such as Gin, Echo, Chi and more.\n\n**Examples on gin:**\n\n```go\npackage main\nimport (\n    \"github.com/gin-gonic/gin/binding\"\n    \"github.com/gookit/validate\"\n)\n\n// implements the binding.StructValidator\ntype customValidator struct {}\n\nfunc (c *customValidator) ValidateStruct(ptr any) error {\n    v := validate.Struct(ptr)\n    v.Validate() // do validating\n    \n    if v.Errors.Empty() {\n\treturn nil\n    }\n\n    return v.Errors\n}\n\nfunc (c *customValidator) Engine() any {\n    return nil\n}\n\nfunc main()  {\n\t// ...\n\n    // after init gin, set custom validator\n    binding.Validator = \u0026customValidator{}\n}\n```\n\n\u003ca id=\"built-in-validators\"\u003e\u003c/a\u003e\n## Built In Validators\n\n\u003e Camel-style validator names now have underlined aliases. `endsWith` can also be written as `ends_with`\n\nvalidator/aliases | description\n-------------------|-------------------------------------------\n`required`  | Check value is required and cannot be empty. \n`required_if/requiredIf`  | `required_if:anotherfield,value,...` The field under validation must be present and not empty if the `anotherField` field is equal to any value.\n`requiredUnless`  | `required_unless:anotherfield,value,...` The field under validation must be present and not empty unless the `anotherField` field is equal to any value. \n`requiredWith`  | `required_with:foo,bar,...` The field under validation must be present and not empty only if any of the other specified fields are present.\n`requiredWithAll`  | `required_with_all:foo,bar,...` The field under validation must be present and not empty only if all of the other specified fields are present.\n`requiredWithout`  | `required_without:foo,bar,...` The field under validation must be present and not empty only when any of the other specified fields are not present.\n`requiredWithoutAll`  | `required_without_all:foo,bar,...` The field under validation must be present and not empty only when all of the other specified fields are not present. \n`-/safe`  | The field values are safe and do not require validation\n`int/integer/isInt`  | Check value is `intX` `uintX` type, And support size checking. eg: `\"int\"` `\"int:2\"` `\"int:2,12\"`\n`uint/isUint`  |  Check value is uint(`uintX`) type, `value \u003e= 0`\n`bool/isBool`  |  Check value is bool string(`true`: \"1\", \"on\", \"yes\", \"true\", `false`: \"0\", \"off\", \"no\", \"false\").\n`string/isString`  |  Check value is string type.\n`float/isFloat`  |  Check value is float(`floatX`) type\n`slice/isSlice`  |  Check value is slice type(`[]intX` `[]uintX` `[]byte` `[]string` ...).\n`in/enum`  |  Check if the value is in the given enumeration `\"in:a,b\"`\n`not_in/notIn`  |  Check if the value is not in the given enumeration `\"contains:b\"`\n`contains`  |  Check if the input value contains the given value\n`not_contains/notContains`  |  Check if the input value not contains the given value\n`string_contains/stringContains`  |  Check if the input string value is contains the given sub-string\n`starts_with/startsWith`  |  Check if the input string value is starts with the given sub-string\n`ends_with/endsWith`  |  Check if the input string value is ends with the given sub-string\n`range/between`  |  Check that the value is a number and is within the given range\n`max/lte`  |  Check value is less than or equal to the given value\n`min/gte`  |  Check value is greater than or equal to the given value(for `intX` `uintX` `floatX`)\n`eq/equal/isEqual`  |  Check that the input value is equal to the given value\n`ne/notEq/notEqual`  |  Check that the input value is not equal to the given value\n`lt/lessThan`  |  Check value is less than the given value(use for `intX` `uintX` `floatX`)\n`gt/greaterThan`  |  Check value is greater than the given value(use for `intX` `uintX` `floatX`)\n`email/isEmail`  |   Check value is email address string.\n`intEq/intEqual`  |  Check value is int and equals to the given value.\n`len/length`  |  Check value length is equals to the given size(use for `string` `array` `slice` `map`).\n`regex/regexp`  |  Check if the value can pass the regular verification\n`arr/list/array/isArray`  |   Check value is array, slice type\n`map/isMap`  |  Check value is a MAP type\n`strings/isStrings`  |  Check value is string slice type(only allow `[]string`).\n`ints/isInts`  |  Check value is int slice type(only allow `[]int`).\n`min_len/minLen/minLength`  |  Check the minimum length of the value is the given size\n`max_len/maxLen/maxLength`  |  Check the maximum length of the value is the given size\n`eq_field/eqField`  |  Check that the field value is equals to the value of another field\n`ne_field/neField`  |  Check that the field value is not equals to the value of another field\n`gte_field/gteField`  |  Check that the field value is greater than or equal to the value of another field\n`gt_field/gtField`  |  Check that the field value is greater than the value of another field\n`lte_field/lteField`  |  Check if the field value is less than or equal to the value of another field\n`lt_field/ltField`  |  Check that the field value is less than the value of another field\n`file/isFile`  |  Verify if it is an uploaded file\n`image/isImage`  |  Check if it is an uploaded image file and support suffix check\n`mime/mimeType/inMimeTypes`  |  Check that it is an uploaded file and is in the specified MIME type\n`date/isDate` | Check the field value is date string. eg `2018-10-25`\n`gt_date/gtDate/afterDate` | Check that the input value is greater than the given date string.\n`lt_date/ltDate/beforeDate` | Check that the input value is less than the given date string\n`gte_date/gteDate/afterOrEqualDate` | Check that the input value is greater than or equal to the given date string.\n`lte_date/lteDate/beforeOrEqualDate` | Check that the input value is less than or equal to the given date string.\n`has_whitespace/hasWhitespace` | Check value string has Whitespace.\n`ascii/ASCII/isASCII` | Check value is ASCII string.\n`alpha/isAlpha` | Verify that the value contains only alphabetic characters\n`alphaNum/isAlphaNum` | Check that only letters, numbers are included\n`alphaDash/isAlphaDash` | Check to include only letters, numbers, dashes ( - ), and underscores ( _ )\n`multiByte/isMultiByte` | Check value is MultiByte string.\n`base64/isBase64` | Check value is Base64 string.\n`dns_name/dnsName/DNSName/isDNSName` | Check value is DNSName string.\n`data_uri/dataURI/isDataURI` | Check value is DataURI string.\n`empty/isEmpty` | Check value is Empty string.\n`hex_color/hexColor/isHexColor` | Check value is Hex color string.\n`hexadecimal/isHexadecimal` | Check value is Hexadecimal string.\n`json/JSON/isJSON` | Check value is JSON string.\n`lat/latitude/isLatitude` | Check value is Latitude string.\n`lon/longitude/isLongitude` | Check value is Longitude string.\n`mac/isMAC` | Check value is MAC string.\n`num/number/isNumber` | Check value is number string. `\u003e= 0`\n`cn_mobile/cnMobile/isCnMobile` | Check value is china mobile number string.\n`printableASCII/isPrintableASCII` | Check value is PrintableASCII string.\n`rgb_color/rgbColor/RGBColor/isRGBColor` | Check value is RGB color string.\n`url/isURL` | Check value is URL string.\n`fullUrl/isFullURL` | Check value is full URL string(_must start with http,https_).\n`ip/isIP`  |  Check value is IP(v4 or v6) string.\n`ipv4/isIPv4`  |  Check value is IPv4 string.\n`ipv6/isIPv6`  |  Check value is IPv6 string.\n`CIDR/isCIDR` | Check value is CIDR string.\n`CIDRv4/isCIDRv4` | Check value is CIDRv4 string.\n`CIDRv6/isCIDRv6` | Check value is CIDRv6 string.\n`uuid/isUUID` | Check value is UUID string.\n`uuid3/isUUID3` | Check value is UUID3 string.\n`uuid4/isUUID4` | Check value is UUID4 string.\n`uuid5/isUUID5` | Check value is UUID5 string.\n`filePath/isFilePath` | Check value is an existing file path\n`unixPath/isUnixPath` | Check value is Unix Path string.\n`winPath/isWinPath` | Check value is Windows Path string.\n`isbn10/ISBN10/isISBN10` | Check value is ISBN10 string.\n`isbn13/ISBN13/isISBN13` | Check value is ISBN13 string.\n\n**Notice:**\n\n- `intX` is contains: int, int8, int16, int32, int64\n- `uintX` is contains: uint, uint8, uint16, uint32, uint64\n- `floatX` is contains: float32, float64\n\n\u003ca id=\"built-in-filters\"\u003e\u003c/a\u003e\n## Built In Filters\n\n\u003e Filters powered by: [gookit/filter](https://github.com/gookit/filter)\n\nfilter/aliases | description \n-------------------|-------------------------------------------\n`int/toInt`  | Convert value(string/intX/floatX) to `int` type `v.FilterRule(\"id\", \"int\")`\n`uint/toUint`  | Convert value(string/intX/floatX) to `uint` type `v.FilterRule(\"id\", \"uint\")`\n`int64/toInt64`  | Convert value(string/intX/floatX) to `int64` type `v.FilterRule(\"id\", \"int64\")`\n`float/toFloat`  | Convert value(string/intX/floatX) to `float` type\n`bool/toBool`   | Convert string value to bool. (`true`: \"1\", \"on\", \"yes\", \"true\", `false`: \"0\", \"off\", \"no\", \"false\")\n`trim/trimSpace`  | Clean up whitespace characters on both sides of the string\n`ltrim/trimLeft`  | Clean up whitespace characters on left sides of the string\n`rtrim/trimRight`  | Clean up whitespace characters on right sides of the string\n`int/integer`  | Convert value(string/intX/floatX) to int type `v.FilterRule(\"id\", \"int\")`\n`lower/lowercase` | Convert string to lowercase\n`upper/uppercase` | Convert string to uppercase\n`lcFirst/lowerFirst` | Convert the first character of a string to lowercase\n`ucFirst/upperFirst` | Convert the first character of a string to uppercase\n`ucWord/upperWord` | Convert the first character of each word to uppercase\n`camel/camelCase` | Convert string to camel naming style\n`snake/snakeCase` | Convert string to snake naming style\n`escapeJs/escapeJS` | Escape JS string.\n`escapeHtml/escapeHTML` | Escape HTML string.\n`str2ints/strToInts` | Convert string to int slice `[]int` \n`str2time/strToTime` | Convert date string to `time.Time`.\n`str2arr/str2array/strToArray` | Convert string to string slice `[]string`\n\n## Gookit packages\n\n- [gookit/ini](https://github.com/gookit/ini) Go config management, use INI files\n- [gookit/rux](https://github.com/gookit/rux) Simple and fast request router for golang HTTP \n- [gookit/gcli](https://github.com/gookit/gcli) build CLI application, tool library, running CLI commands\n- [gookit/event](https://github.com/gookit/event) Lightweight event manager and dispatcher implements by Go\n- [gookit/cache](https://github.com/gookit/cache) Generic cache use and cache manager for golang. support File, Memory, Redis, Memcached.\n- [gookit/config](https://github.com/gookit/config) Go config management. support JSON, YAML, TOML, INI, HCL, ENV and Flags\n- [gookit/color](https://github.com/gookit/color) A command-line color library with true color support, universal API methods and Windows support\n- [gookit/filter](https://github.com/gookit/filter) Provide filtering, sanitizing, and conversion of golang data\n- [gookit/validate](https://github.com/gookit/validate) Use for data validation and filtering. support Map, Struct, Form data\n- [gookit/goutil](https://github.com/gookit/goutil) Some utils for the Go: string, array/slice, map, format, cli, env, filesystem, test and more\n- More please see https://github.com/gookit\n\n## See also\n\n- https://github.com/albrow/forms\n- https://github.com/asaskevich/govalidator\n- https://github.com/go-playground/validator\n- https://github.com/inhere/php-validate\n\n## License\n\n**[MIT](LICENSE)**\n","funding_links":[],"categories":["Validation","Miscellaneous","Go","Utility","校验库","验证","校验库`用于校验的库`"],"sub_categories":["Utility/Miscellaneous","HTTP Clients","Fail injection","查询语","实用程序/Miscellaneous"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fvalidate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgookit%2Fvalidate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fvalidate/lists"}