{"id":37096825,"url":"https://github.com/zippoxer/validator","last_synced_at":"2026-01-14T11:54:52.214Z","repository":{"id":141351690,"uuid":"59906887","full_name":"zippoxer/validator","owner":"zippoxer","description":"Package validator implements struct field validations","archived":false,"fork":true,"pushed_at":"2016-02-11T00:12:57.000Z","size":89,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"v2","last_synced_at":"2025-09-09T16:23:22.282Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"go-validator/validator","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zippoxer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-28T17:35:08.000Z","updated_at":"2016-05-28T17:35:09.000Z","dependencies_parsed_at":"2023-04-30T10:47:49.572Z","dependency_job_id":null,"html_url":"https://github.com/zippoxer/validator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zippoxer/validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zippoxer%2Fvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zippoxer%2Fvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zippoxer%2Fvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zippoxer%2Fvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zippoxer","download_url":"https://codeload.github.com/zippoxer/validator/tar.gz/refs/heads/v2","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zippoxer%2Fvalidator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-01-14T11:54:51.667Z","updated_at":"2026-01-14T11:54:52.203Z","avatar_url":"https://github.com/zippoxer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Package validator\n================\n\nPackage validator implements variable validations\n\nInstallation\n============\n\nJust use go get.\n\n\tgo get gopkg.in/validator.v2\n\nAnd then just import the package into your own code.\n\n\timport (\n\t\t\"gopkg.in/validator.v2\"\n\t)\n\nUsage\n=====\n\nPlease see http://godoc.org/gopkg.in/validator.v2 for detailed usage docs.\nA simple example would be.\n\n\ttype NewUserRequest struct {\n\t\tUsername string `validate:\"min=3,max=40,regexp=^[a-zA-Z]*$\"`\n\t\tName string     `validate:\"nonzero\"`\n\t\tAge int         `validate:\"min=21\"`\n\t\tPassword string `validate:\"min=8\"`\n\t}\n\n\tnur := NewUserRequest{Username: \"something\", Age: 20}\n\tif errs := validator.Validate(nur); errs != nil {\n\t\t// values not valid, deal with errors here\n\t}\n\n\nBuiltin validators\n\nHere is the list of validators buildin in the package.\n\n\tlen\n\t\tFor numeric numbers, max will simply make sure that the\n\t\tvalue is equal to the parameter given. For strings, it\n\t\tchecks that the string length is exactly that number of\n\t\tcharacters. For slices,\tarrays, and maps, validates the\n\t\tnumber of items. (Usage: len=10)\n\t\n\tmax\n\t\tFor numeric numbers, max will simply make sure that the\n\t\tvalue is lesser or equal to the parameter given. For strings,\n\t\tit checks that the string length is at most that number of\n\t\tcharacters. For slices,\tarrays, and maps, validates the\n\t\tnumber of items. (Usage: max=10)\n\t\n\tmin\n\t\tFor numeric numbers, min will simply make sure that the value\n\t\tis greater or equal to the parameter given. For strings, it\n\t\tchecks that the string length is at least that number of\n\t\tcharacters. For slices, arrays, and maps, validates the\n\t\tnumber of items. (Usage: min=10)\n\t\n\tnonzero\n\t\tThis validates that the value is not zero. The appropriate\n\t\tzero value is given by the Go spec (e.g. for int it's 0, for\n\t\tstring it's \"\", for pointers is nil, etc.) For structs, it\n\t\twill not check to see if the struct itself has all zero\n\t\tvalues, instead use a pointer or put nonzero on the struct's\n\t\tkeys that you care about. (Usage: nonzero)\n\t\n\tregexp\n\t\tOnly valid for string types, it will validator that the\n\t\tvalue matches the regular expression provided as parameter.\n\t\t(Usage: regexp=^a.*b$)\n\nCustom validators\n\nIt is possible to define custom validators by using SetValidationFunc.\nFirst, one needs to create a validation function.\n\n\t// Very simple validator\n\tfunc notZZ(v interface{}, param string) error {\n\t\tst := reflect.ValueOf(v)\n\t\tif st.Kind() != reflect.String {\n\t\t\treturn errors.New(\"notZZ only validates strings\")\n\t\t}\n\t\tif st.String() == \"ZZ\" {\n\t\t\treturn errors.New(\"value cannot be ZZ\")\n\t\t}\n\t\treturn nil\n\t}\n\nThen one needs to add it to the list of validators and give it a \"tag\"\nname.\n\n\tvalidator.SetValidationFunc(\"notzz\", notZZ)\n\nThen it is possible to use the notzz validation tag. This will print\n\"Field A error: value cannot be ZZ\"\n\n\ttype T struct {\n\t\tA string  `validate:\"nonzero,notzz\"`\n\t}\n\tt := T{\"ZZ\"}\n\tif errs := validator.Validate(t); errs != nil {\n\t\tfmt.Printf(\"Field A error: %s\\n\", errs[\"A\"][0])\n\t}\n\nYou can also have multiple sets of validator rules with SetTag().\n\n\ttype T struct {\n\t\tA int `foo:\"nonzero\" bar:\"min=10\"`\n\t}\n\tt := T{5}\n\tSetTag(\"foo\")\n\tvalidator.Validate(t) // valid as it's nonzero\n\tSetTag(\"bar\")\n\tvalidator.Validate(t) // invalid as it's less than 10\n\nSetTag is probably better used with multiple validators.\n\n\tfooValidator := validator.NewValidator()\n\tfooValidator.SetTag(\"foo\")\n\tbarValidator := validator.NewValidator()\n\tbarValidator.SetTag(\"bar\")\n\tfooValidator.Validate(t)\n\tbarValidator.Validate(t)\n\nThis keeps the default validator's tag clean. Again, please refer to\ngodocs for a lot of more examples and different uses.\n\nPull requests policy\n====================\n\ntl;dr. Contributions are welcome.\n\nThe repository is organized in version branches. Pull requests to, say, the\n`v2` branch that break API compatibility will not be accepted. It is okay to\nbreak the API in master, *not in the branches*.\n\nAs for validation functions, the preference is to keep the main code simple\nand add most new functions to the validator-contrib repository.\n\nhttps://github.com/go-validator/validator-contrib\n\nFor improvements and/or fixes to the builtin validation functions, please\nmake sure the behaviour will not break existing functionality in the branches.\nIf you see a case where the functionality of the builtin will change\nsignificantly, please send a pull request against `master`. We can discuss then\nwhether the changes should be incorporated in the version branches as well.\n\nLicense\n=======\n\nCopyright 2014 Roberto Teixeira \u003crobteix@robteix.com\u003e\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzippoxer%2Fvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzippoxer%2Fvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzippoxer%2Fvalidator/lists"}