{"id":3800859,"name":"github.com/vikyd/validator","ecosystem":"go","description":"Package validator implements value validations for structs and individual fields\nbased on tags.\n\nIt can also handle Cross-Field and Cross-Struct validation for nested structs\nand has the ability to dive into arrays and maps of any type.\n\nsee more examples https://github.com/go-playground/validator/tree/v9/_examples\n\nDoing things this way is actually the way the standard library does, see the\nfile.Open method here:\n\nThe authors return type \"error\" to avoid the issue discussed in the following,\nwhere err is always != nil:\n\nValidator only InvalidValidationError for bad validation input, nil or\nValidationErrors as type error; so, in your code all you need to do is check\nif the error returned is not nil, and if it's not check if error is\nInvalidValidationError ( if necessary, most of the time it isn't ) type cast\nit to type ValidationErrors like so err.(validator.ValidationErrors).\n\nCustom Validation functions can be added. Example:\n\nCross-Field Validation can be done via the following tags:\n\nIf, however, some custom cross-field validation is required, it can be done\nusing a custom validation.\n\nWhy not just have cross-fields validation tags (i.e. only eqcsfield and not\neqfield)?\n\nThe reason is efficiency. If you want to check a field within the same struct\n\"eqfield\" only has to find the field on the same struct (1 level). But, if we\nused \"eqcsfield\" it could be multiple levels down. Example:\n\nMultiple validators on a field will process in the order defined. Example:\n\nBad Validator definitions are not handled by the library. Example:\n\nBaked In Cross-Field validation only compares fields on the same struct.\nIf Cross-Field + Cross-Struct validation is needed you should implement your\nown custom validator.\n\nComma (\",\") is the default separator of validation tags. If you wish to\nhave a comma included within the parameter (i.e. excludesall=,) you will need to\nuse the UTF-8 hex representation 0x2C, which is replaced in the code as a comma,\nso the above will become excludesall=0x2C.\n\nPipe (\"|\") is the 'or' validation tags deparator. If you wish to\nhave a pipe included within the parameter i.e. excludesall=| you will need to\nuse the UTF-8 hex representation 0x7C, which is replaced in the code as a pipe,\nso the above will become excludesall=0x7C\n\nHere is a list of the current built in validators:\n\nTells the validation to skip this struct field; this is particularly\nhandy in ignoring embedded structs from being validated. (Usage: -)\n\nThis is the 'or' operator allowing multiple validators to be used and\naccepted. (Usage: rbg|rgba) \u003c-- this would allow either rgb or rgba\ncolors to be accepted. This can also be combined with 'and' for example\n( Usage: omitempty,rgb|rgba)\n\nWhen a field that is a nested struct is encountered, and contains this flag\nany validation on the nested struct will be run, but none of the nested\nstruct fields will be validated. This is useful if inside of your program\nyou know the struct will be valid, but need to verify it has been assigned.\nNOTE: only \"required\" and \"omitempty\" can be used on a struct itself.\n\nSame as structonly tag except that any struct level validations will not run.\n\nAllows conditional validation, for example if a field is not set with\na value (Determined by the \"required\" validator) then other validation\nsuch as min or max won't run, but if a value is set validation will run.\n\nThis tells the validator to dive into a slice, array or map and validate that\nlevel of the slice, array or map with the validation tags that follow.\nMultidimensional nesting is also supported, each level you wish to dive will\nrequire another dive tag. dive has some sub-tags, 'keys' \u0026 'endkeys', please see\nthe Keys \u0026 EndKeys section just below.\n\nExample #1\n\nExample #2\n\nKeys \u0026 EndKeys\n\nThese are to be used together directly after the dive tag and tells the validator\nthat anything between 'keys' and 'endkeys' applies to the keys of a map and not the\nvalues; think of it like the 'dive' tag, but for map keys instead of values.\nMultidimensional nesting is also supported, each level you wish to validate will\nrequire another 'keys' and 'endkeys' tag. These tags are only valid for maps.\n\nExample #1\n\nExample #2\n\nThis validates that the value is not the data types default zero value.\nFor numbers ensures value is not zero. For strings ensures value is\nnot \"\". For slices, maps, pointers, interfaces, channels and functions\nensures the value is not nil.\n\nThe field under validation must be present and not empty only if any\nof the other specified fields are present. For strings ensures value is\nnot \"\". For slices, maps, pointers, interfaces, channels and functions\nensures the value is not nil.\n\nExamples:\n\nThe field under validation must be present and not empty only if all\nof the other specified fields are present. For strings ensures value is\nnot \"\". For slices, maps, pointers, interfaces, channels and functions\nensures the value is not nil.\n\nExample:\n\nThe field under validation must be present and not empty only when any\nof the other specified fields are not present. For strings ensures value is\nnot \"\". For slices, maps, pointers, interfaces, channels and functions\nensures the value is not nil.\n\nExamples:\n\nThe field under validation must be present and not empty only when all\nof the other specified fields are not present. For strings ensures value is\nnot \"\". For slices, maps, pointers, interfaces, channels and functions\nensures the value is not nil.\n\nExample:\n\nThis validates that the value is the default value and is almost the\nopposite of required.\n\nFor numbers, length will ensure that the value is\nequal to the parameter given. For strings, it checks that\nthe string length is exactly that number of characters. For slices,\narrays, and maps, validates the number of items.\n\nFor numbers, max will ensure that the value is\nless than or equal to the parameter given. For strings, it checks\nthat the string length is at most that number of characters. For\nslices, arrays, and maps, validates the number of items.\n\nFor numbers, min will ensure that the value is\ngreater or equal to the parameter given. For strings, it checks that\nthe string length is at least that number of characters. For slices,\narrays, and maps, validates the number of items.\n\nFor strings \u0026 numbers, eq will ensure that the value is\nequal to the parameter given. For slices, arrays, and maps,\nvalidates the number of items.\n\nFor strings \u0026 numbers, ne will ensure that the value is not\nequal to the parameter given. For slices, arrays, and maps,\nvalidates the number of items.\n\nFor strings, ints, and uints, oneof will ensure that the value\nis one of the values in the parameter.  The parameter should be\na list of values separated by whitespace.  Values may be\nstrings or numbers.\n\nFor numbers, this will ensure that the value is greater than the\nparameter given. For strings, it checks that the string length\nis greater than that number of characters. For slices, arrays\nand maps it validates the number of items.\n\nExample #1\n\nExample #2 (time.Time)\n\nFor time.Time ensures the time value is greater than time.Now.UTC().\n\nSame as 'min' above. Kept both to make terminology with 'len' easier.\n\nExample #1\n\nExample #2 (time.Time)\n\nFor time.Time ensures the time value is greater than or equal to time.Now.UTC().\n\nFor numbers, this will ensure that the value is less than the parameter given.\nFor strings, it checks that the string length is less than that number of\ncharacters. For slices, arrays, and maps it validates the number of items.\n\nExample #1\n\nExample #2 (time.Time)\nFor time.Time ensures the time value is less than time.Now.UTC().\n\nSame as 'max' above. Kept both to make terminology with 'len' easier.\n\nExample #1\n\nExample #2 (time.Time)\n\nFor time.Time ensures the time value is less than or equal to time.Now.UTC().\n\nThis will validate the field value against another fields value either within\na struct or passed in field.\n\nExample #1:\n\nExample #2:\n\nField Equals Another Field (relative)\n\nThis does the same as eqfield except that it validates the field provided relative\nto the top level struct.\n\nThis will validate the field value against another fields value either within\na struct or passed in field.\n\nExamples:\n\nField Does Not Equal Another Field (relative)\n\nThis does the same as nefield except that it validates the field provided\nrelative to the top level struct.\n\nOnly valid for Numbers and time.Time types, this will validate the field value\nagainst another fields value either within a struct or passed in field.\nusage examples are for validation of a Start and End date:\n\nExample #1:\n\nExample #2:\n\nThis does the same as gtfield except that it validates the field provided\nrelative to the top level struct.\n\nOnly valid for Numbers and time.Time types, this will validate the field value\nagainst another fields value either within a struct or passed in field.\nusage examples are for validation of a Start and End date:\n\nExample #1:\n\nExample #2:\n\nThis does the same as gtefield except that it validates the field provided relative\nto the top level struct.\n\nOnly valid for Numbers and time.Time types, this will validate the field value\nagainst another fields value either within a struct or passed in field.\nusage examples are for validation of a Start and End date:\n\nExample #1:\n\nExample #2:\n\nThis does the same as ltfield except that it validates the field provided relative\nto the top level struct.\n\nOnly valid for Numbers and time.Time types, this will validate the field value\nagainst another fields value either within a struct or passed in field.\nusage examples are for validation of a Start and End date:\n\nExample #1:\n\nExample #2:\n\nThis does the same as ltefield except that it validates the field provided relative\nto the top level struct.\n\nThis does the same as contains except for struct fields. It should only be used\nwith string types. See the behavior of reflect.Value.String() for behavior on\nother types.\n\nThis does the same as excludes except for struct fields. It should only be used\nwith string types. See the behavior of reflect.Value.String() for behavior on\nother types.\n\nFor arrays \u0026 slices, unique will ensure that there are no duplicates.\nFor maps, unique will ensure that there are no duplicate values.\nFor slices of struct, unique will ensure that there are no duplicate values\nin a field of the struct specified via a parameter.\n\nThis validates that a string value contains ASCII alpha characters only\n\nThis validates that a string value contains ASCII alphanumeric characters only\n\nThis validates that a string value contains unicode alpha characters only\n\nThis validates that a string value contains unicode alphanumeric characters only\n\nThis validates that a string value contains a basic numeric value.\nbasic excludes exponents etc...\nfor integers or float it returns true.\n\nThis validates that a string value contains a valid hexadecimal.\n\nThis validates that a string value contains a valid hex color including\nhashtag (#)\n\nThis validates that a string value contains a valid rgb color\n\nThis validates that a string value contains a valid rgba color\n\nThis validates that a string value contains a valid hsl color\n\nThis validates that a string value contains a valid hsla color\n\nThis validates that a string value contains a valid email\nThis may not conform to all possibilities of any rfc standard, but neither\ndoes any email provider accept all possibilities.\n\nThis validates that a string value contains a valid file path and that\nthe file exists on the machine.\nThis is done using os.Stat, which is a platform independent function.\n\nThis validates that a string value contains a valid url\nThis will accept any url the golang request uri accepts but must contain\na schema for example http:// or rtmp://\n\nThis validates that a string value contains a valid uri\nThis will accept any uri the golang request uri accepts\n\nThis validataes that a string value contains a valid URN\naccording to the RFC 2141 spec.\n\nThis validates that a string value contains a valid base64 value.\nAlthough an empty string is valid base64 this will report an empty string\nas an error, if you wish to accept an empty string as valid you can use\nthis with the omitempty tag.\n\nThis validates that a string value contains a valid base64 URL safe value\naccording the the RFC4648 spec.\nAlthough an empty string is a valid base64 URL safe value, this will report\nan empty string as an error, if you wish to accept an empty string as valid\nyou can use this with the omitempty tag.\n\nThis validates that a string value contains a valid bitcoin address.\nThe format of the string is checked to ensure it matches one of the three formats\nP2PKH, P2SH and performs checksum validation.\n\nBitcoin Bech32 Address (segwit)\n\nThis validates that a string value contains a valid bitcoin Bech32 address as defined\nby bip-0173 (https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki)\nSpecial thanks to Pieter Wuille for providng reference implementations.\n\nThis validates that a string value contains a valid ethereum address.\nThe format of the string is checked to ensure it matches the standard Ethereum address format\nFull validation is blocked by https://github.com/golang/crypto/pull/28\n\nThis validates that a string value contains the substring value.\n\nThis validates that a string value contains any Unicode code points\nin the substring value.\n\nThis validates that a string value contains the supplied rune value.\n\nThis validates that a string value does not contain the substring value.\n\nThis validates that a string value does not contain any Unicode code\npoints in the substring value.\n\nThis validates that a string value does not contain the supplied rune value.\n\nThis validates that a string value starts with the supplied string value\n\nThis validates that a string value ends with the supplied string value\n\nThis validates that a string value contains a valid isbn10 or isbn13 value.\n\nThis validates that a string value contains a valid isbn10 value.\n\nThis validates that a string value contains a valid isbn13 value.\n\nThis validates that a string value contains a valid UUID. Uppercase UUID values will not pass - use `uuid_rfc4122` instead.\n\nThis validates that a string value contains a valid version 3 UUID.  Uppercase UUID values will not pass - use `uuid3_rfc4122` instead.\n\nThis validates that a string value contains a valid version 4 UUID.  Uppercase UUID values will not pass - use `uuid4_rfc4122` instead.\n\nThis validates that a string value contains a valid version 5 UUID.  Uppercase UUID values will not pass - use `uuid5_rfc4122` instead.\n\nThis validates that a string value contains only ASCII characters.\nNOTE: if the string is blank, this validates as true.\n\nThis validates that a string value contains only printable ASCII characters.\nNOTE: if the string is blank, this validates as true.\n\nThis validates that a string value contains one or more multibyte characters.\nNOTE: if the string is blank, this validates as true.\n\nThis validates that a string value contains a valid DataURI.\nNOTE: this will also validate that the data portion is valid base64\n\nThis validates that a string value contains a valid latitude.\n\nThis validates that a string value contains a valid longitude.\n\nThis validates that a string value contains a valid U.S. Social Security Number.\n\nThis validates that a string value contains a valid IP Address.\n\nThis validates that a string value contains a valid v4 IP Address.\n\nThis validates that a string value contains a valid v6 IP Address.\n\nThis validates that a string value contains a valid CIDR Address.\n\nThis validates that a string value contains a valid v4 CIDR Address.\n\nThis validates that a string value contains a valid v6 CIDR Address.\n\nThis validates that a string value contains a valid resolvable TCP Address.\n\nThis validates that a string value contains a valid resolvable v4 TCP Address.\n\nThis validates that a string value contains a valid resolvable v6 TCP Address.\n\nThis validates that a string value contains a valid resolvable UDP Address.\n\nThis validates that a string value contains a valid resolvable v4 UDP Address.\n\nThis validates that a string value contains a valid resolvable v6 UDP Address.\n\nThis validates that a string value contains a valid resolvable IP Address.\n\nThis validates that a string value contains a valid resolvable v4 IP Address.\n\nThis validates that a string value contains a valid resolvable v6 IP Address.\n\nThis validates that a string value contains a valid Unix Address.\n\nThis validates that a string value contains a valid MAC Address.\n\nNote: See Go's ParseMAC for accepted formats and types:\n\nThis validates that a string value is a valid Hostname according to RFC 952 https://tools.ietf.org/html/rfc952\n\nThis validates that a string value is a valid Hostname according to RFC 1123 https://tools.ietf.org/html/rfc1123\n\nFull Qualified Domain Name (FQDN)\n\nThis validates that a string value contains a valid FQDN.\n\nThis validates that a string value appears to be an HTML element tag\nincluding those described at https://developer.mozilla.org/en-US/docs/Web/HTML/Element\n\nThis validates that a string value is a proper character reference in decimal\nor hexadecimal format\n\nThis validates that a string value is percent-encoded (URL encoded) according\nto https://tools.ietf.org/html/rfc3986#section-2.1\n\nThis validates that a string value contains a valid directory and that\nit exists on the machine.\nThis is done using os.Stat, which is a platform independent function.\n\nNOTE: When returning an error, the tag returned in \"FieldError\" will be\nthe alias tag unless the dive tag is part of the alias. Everything after the\ndive tag is not reported as the alias tag. Also, the \"ActualTag\" in the before\ncase will be the actual tag within the alias that failed.\n\nHere is a list of the current built in alias tags:\n\nValidator notes:\n\nA collection of validation rules that are frequently needed but are more\ncomplex than the ones found in the baked in validators.\nA non standard validator must be registered manually like you would\nwith your own custom validation functions.\n\nExample of registration and use:\n\nHere is a list of the current non standard validators:\n\nThis package panics when bad input is provided, this is by design, bad code like\nthat should not make it to production.","homepage":"https://github.com/vikyd/validator","licenses":"MIT","normalized_licenses":["MIT"],"repository_url":"https://github.com/vikyd/validator","keywords_array":[],"namespace":"github.com/vikyd","versions_count":82,"first_release_published_at":"2015-03-19T19:55:53.000Z","latest_release_published_at":"2019-12-25T05:24:06.000Z","latest_release_number":"v9.31.0+incompatible","last_synced_at":"2026-05-28T11:46:21.147Z","created_at":"2022-04-11T18:24:26.126Z","updated_at":"2026-05-28T11:46:21.147Z","registry_url":"https://pkg.go.dev/github.com/vikyd/validator","install_command":"go get github.com/vikyd/validator","documentation_url":"https://pkg.go.dev/github.com/vikyd/validator#section-documentation","metadata":{},"repo_metadata":{},"repo_metadata_updated_at":"2023-03-21T19:06:37.037Z","dependent_packages_count":0,"downloads":null,"downloads_period":null,"dependent_repos_count":0,"rankings":{"downloads":null,"dependent_repos_count":9.345852080216646,"dependent_packages_count":6.999148183520997,"stargazers_count":null,"forks_count":null,"average":8.172500131868823},"purl":"pkg:golang/github.com/vikyd/validator","advisories":[],"docker_usage_url":"https://docker.ecosyste.ms/usage/go/github.com/vikyd/validator","docker_dependents_count":null,"docker_downloads_count":null,"usage_url":"https://repos.ecosyste.ms/usage/go/github.com/vikyd/validator","dependent_repositories_url":"https://repos.ecosyste.ms/api/v1/usage/go/github.com/vikyd/validator/dependencies","status":null,"funding_links":[],"critical":null,"issue_metadata":null,"versions_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2Fvikyd%2Fvalidator/versions","version_numbers_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2Fvikyd%2Fvalidator/version_numbers","latest_version_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2Fvikyd%2Fvalidator/latest_version","dependent_packages_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2Fvikyd%2Fvalidator/dependent_packages","related_packages_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2Fvikyd%2Fvalidator/related_packages","codemeta_url":"https://packages.ecosyste.ms/api/v1/registries/proxy.golang.org/packages/github.com%2Fvikyd%2Fvalidator/codemeta","maintainers":[]}