|
1 | 1 | Package validator |
2 | 2 | ================ |
3 | 3 | <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) |
4 | | - |
| 4 | + |
5 | 5 | [](https://travis-ci.org/go-playground/validator) |
6 | 6 | [](https://coveralls.io/github/go-playground/validator?branch=master) |
7 | 7 | [](https://goreportcard.com/report/github.com/go-playground/validator) |
8 | | -[](https://godoc.org/github.com/go-playground/validator) |
| 8 | +[](https://pkg.go.dev/github.com/go-playground/validator/v10) |
9 | 9 |  |
10 | 10 |
|
11 | 11 | Package validator implements value validations for structs and individual fields based on tags. |
12 | 12 |
|
13 | 13 | It has the following **unique** features: |
14 | 14 |
|
15 | | -- Cross Field and Cross Struct validations by using validation tags or custom validators. |
| 15 | +- Cross Field and Cross Struct validations by using validation tags or custom validators. |
16 | 16 | - Slice, Array and Map diving, which allows any or all levels of a multidimensional field to be validated. |
17 | | -- Ability to dive into both map keys and values for validation |
| 17 | +- Ability to dive into both map keys and values for validation |
18 | 18 | - Handles type interface by determining it's underlying type prior to validation. |
19 | 19 | - Handles custom field types such as sql driver Valuer see [Valuer](https://golang.org/src/database/sql/driver/types.go?s=1210:1293#L29) |
20 | 20 | - Alias validation tags, which allows for mapping of several validations to a single tag for easier defining of validations on structs |
@@ -64,6 +64,145 @@ Please see https://godoc.org/github.com/go-playground/validator for detailed usa |
64 | 64 | - [Gin upgrade and/or override validator](https://github.com/go-playground/validator/tree/v9/_examples/gin-upgrading-overriding) |
65 | 65 | - [wash - an example application putting it all together](https://github.com/bluesuncorp/wash) |
66 | 66 |
|
| 67 | +Baked-in Validations |
| 68 | +------ |
| 69 | + |
| 70 | +### Fields: |
| 71 | + |
| 72 | +| Tag | Description | |
| 73 | +| - | - | |
| 74 | +| eqcsfield | Field Equals Another Field (relative)| |
| 75 | +| eqfield | Field Equals Another Field | |
| 76 | +| fieldcontains | NOT DOCUMENTED IN doc.go | |
| 77 | +| fieldexcludes | NOT DOCUMENTED IN doc.go | |
| 78 | +| gtcsfield | Field Greater Than Another Relative Field | |
| 79 | +| gtecsfield | Field Greater Than or Equal To Another Relative Field | |
| 80 | +| gtefield | Field Greater Than or Equal To Another Field | |
| 81 | +| gtfield | Field Greater Than Another Field | |
| 82 | +| ltcsfield | Less Than Another Relative Field | |
| 83 | +| ltecsfield | Less Than or Equal To Another Relative Field | |
| 84 | +| ltefield | Less Than or Equal To Another Field | |
| 85 | +| ltfield | Less Than Another Field | |
| 86 | +| necsfield | Field Does Not Equal Another Field (relative) | |
| 87 | +| nefield | Field Does Not Equal Another Field | |
| 88 | + |
| 89 | +### Network: |
| 90 | + |
| 91 | +| Tag | Description | |
| 92 | +| - | - | |
| 93 | +| cidr | Classless Inter-Domain Routing CIDR | |
| 94 | +| cidrv4 | Classless Inter-Domain Routing CIDRv4 | |
| 95 | +| cidrv6 | Classless Inter-Domain Routing CIDRv6 | |
| 96 | +| datauri | Data URL | |
| 97 | +| fqdn | Full Qualified Domain Name (FQDN) | |
| 98 | +| hostname | Hostname RFC 952 | |
| 99 | +| hostname_port | HostPort | |
| 100 | +| hostname_rfc1123 | Hostname RFC 1123 | |
| 101 | +| ip | Internet Protocol Address IP | |
| 102 | +| ip4_addr | Internet Protocol Address IPv4 | |
| 103 | +| ip6_addr |Internet Protocol Address IPv6 | |
| 104 | +| ip_addr | Internet Protocol Address IP | |
| 105 | +| ipv4 | Internet Protocol Address IPv4 | |
| 106 | +| ipv6 | Internet Protocol Address IPv6 | |
| 107 | +| mac | Media Access Control Address MAC | |
| 108 | +| tcp4_addr | Transmission Control Protocol Address TCPv4 | |
| 109 | +| tcp6_addr | Transmission Control Protocol Address TCPv6 | |
| 110 | +| tcp_addr | Transmission Control Protocol Address TCP | |
| 111 | +| udp4_addr | User Datagram Protocol Address UDPv4 | |
| 112 | +| udp6_addr | User Datagram Protocol Address UDPv6 | |
| 113 | +| udp_addr | User Datagram Protocol Address UDP | |
| 114 | +| unix_addr | Unix domain socket end point Address | |
| 115 | +| uri | URI String | |
| 116 | +| url | URL String | |
| 117 | +| url_encoded | URL Encoded | |
| 118 | +| urn_rfc2141 | Urn RFC 2141 String | |
| 119 | + |
| 120 | +### Strings: |
| 121 | + |
| 122 | +| Tag | Description | |
| 123 | +| - | - | |
| 124 | +| alpha | Alpha Only | |
| 125 | +| alphanum | Alphanumeric | |
| 126 | +| alphanumunicode | Alphanumeric Unicode | |
| 127 | +| alphaunicode | Alpha Unicode | |
| 128 | +| ascii | ASCII | |
| 129 | +| contains | Contains | |
| 130 | +| containsany | Contains Any | |
| 131 | +| containsrune | Contains Rune | |
| 132 | +| lowercase | Lowercase | |
| 133 | +| multibyte | Multi-Byte Characters | |
| 134 | +| number | NOT DOCUMENTED IN doc.go | |
| 135 | +| numeric | Numeric | |
| 136 | +| printascii | Printable ASCII | |
| 137 | +| startswith | Starts With | |
| 138 | +| uppercase | Uppercase | |
| 139 | + |
| 140 | +### Format: |
| 141 | +| Tag | Description | |
| 142 | +| - | - | |
| 143 | +| base64 | Base64 String | |
| 144 | +| base64url | Base64URL String | |
| 145 | +| btc_addr | Bitcoin Address | |
| 146 | +| btc_addr_bech32 | Bitcoin Bech32 Address (segwit) | |
| 147 | +| datetime | Datetime | |
| 148 | +| email | E-mail String |
| 149 | +| eth_addr | Ethereum Address | |
| 150 | +| hexadecimal | Hexadecimal String | |
| 151 | +| hexcolor | Hexcolor String | |
| 152 | +| hsl | HSL String | |
| 153 | +| hsla | HSLA String | |
| 154 | +| html | HTML Tags | |
| 155 | +| html_encoded | HTML Encoded | |
| 156 | +| isbn | International Standard Book Number | |
| 157 | +| isbn10 | International Standard Book Number 10 | |
| 158 | +| isbn13 | International Standard Book Number 13 | |
| 159 | +| json | JSON | |
| 160 | +| latitude | Latitude | |
| 161 | +| longitude | Longitude | |
| 162 | +| rgb | RGB String | |
| 163 | +| rgba | RGBA String | |
| 164 | +| ssn | Social Security Number SSN | |
| 165 | +| uuid | Universally Unique Identifier UUID | |
| 166 | +| uuid3 | Universally Unique Identifier UUID v3 | |
| 167 | +| uuid3_rfc4122 | Universally Unique Identifier UUID v3 RFC4122 | |
| 168 | +| uuid4 | Universally Unique Identifier UUID v4 | |
| 169 | +| uuid4_rfc4122 | Universally Unique Identifier UUID v4 RFC4122 | |
| 170 | +| uuid5 | Universally Unique Identifier UUID v5 | |
| 171 | +| uuid5_rfc4122 | Universally Unique Identifier UUID v5 RFC4122 | |
| 172 | +| uuid_rfc4122 | Universally Unique Identifier UUID RFC4122 | |
| 173 | + |
| 174 | +### Comparisons: |
| 175 | +| Tag | Description | |
| 176 | +| - | - | |
| 177 | +| eq | Equals | |
| 178 | +| gt | Greater than| |
| 179 | +| gte |Greater than or equal | |
| 180 | +| lt | Less Than | |
| 181 | +| lte | Less Than or Equal | |
| 182 | +| ne | Not Equal | |
| 183 | + |
| 184 | +### Other: |
| 185 | +| Tag | Description | |
| 186 | +| - | - | |
| 187 | +| dir | Directory | |
| 188 | +| e164 | NOT DOCUMENTED IN doc.go | |
| 189 | +| endswith | Ends With | |
| 190 | +| excludes | Excludes | |
| 191 | +| excludesall | Excludes All | |
| 192 | +| excludesrune | Excludes Rune | |
| 193 | +| file | File path | |
| 194 | +| isdefault | Is Default | |
| 195 | +| len | Length | |
| 196 | +| max | Maximum | |
| 197 | +| min | Minimum | |
| 198 | +| oneof | One Of | |
| 199 | +| required | Required | |
| 200 | +| required_with | Required With | |
| 201 | +| required_with_all | Required With All | |
| 202 | +| required_without | Required Without | |
| 203 | +| required_without_all | Required Without All | |
| 204 | +| unique | Unique | |
| 205 | + |
67 | 206 | Benchmarks |
68 | 207 | ------ |
69 | 208 | ###### Run on MacBook Pro (15-inch, 2017) go version go1.10.2 darwin/amd64 |
|
0 commit comments