checker/DOC.md
Onur Cinar ea60113fa1
Time check is added. (#162)
# Describe Request

Time check is added.

# Change Type

New checker.
2025-01-03 10:35:34 -08:00

1523 lines
No EOL
29 KiB
Markdown

<!-- gomarkdoc:embed:start -->
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
# v2
```go
import "github.com/cinar/checker/v2"
```
Package v2 Checker is a Go library for validating user input through checker rules provided in struct tags.
## Index
- [Constants](<#constants>)
- [Variables](<#variables>)
- [func Check\[T any\]\(value T, checks ...CheckFunc\[T\]\) \(T, error\)](<#Check>)
- [func CheckStruct\(st any\) \(map\[string\]error, bool\)](<#CheckStruct>)
- [func CheckWithConfig\[T any\]\(value T, config string\) \(T, error\)](<#CheckWithConfig>)
- [func HTMLEscape\(value string\) \(string, error\)](<#HTMLEscape>)
- [func HTMLUnescape\(value string\) \(string, error\)](<#HTMLUnescape>)
- [func IsASCII\(value string\) \(string, error\)](<#IsASCII>)
- [func IsAlphanumeric\(value string\) \(string, error\)](<#IsAlphanumeric>)
- [func IsAmexCreditCard\(number string\) \(string, error\)](<#IsAmexCreditCard>)
- [func IsAnyCreditCard\(number string\) \(string, error\)](<#IsAnyCreditCard>)
- [func IsCIDR\(value string\) \(string, error\)](<#IsCIDR>)
- [func IsDigits\(value string\) \(string, error\)](<#IsDigits>)
- [func IsDinersCreditCard\(number string\) \(string, error\)](<#IsDinersCreditCard>)
- [func IsDiscoverCreditCard\(number string\) \(string, error\)](<#IsDiscoverCreditCard>)
- [func IsEmail\(value string\) \(string, error\)](<#IsEmail>)
- [func IsFQDN\(value string\) \(string, error\)](<#IsFQDN>)
- [func IsGte\[T cmp.Ordered\]\(value, n T\) \(T, error\)](<#IsGte>)
- [func IsHex\(value string\) \(string, error\)](<#IsHex>)
- [func IsIP\(value string\) \(string, error\)](<#IsIP>)
- [func IsIPv4\(value string\) \(string, error\)](<#IsIPv4>)
- [func IsIPv6\(value string\) \(string, error\)](<#IsIPv6>)
- [func IsISBN\(value string\) \(string, error\)](<#IsISBN>)
- [func IsJcbCreditCard\(number string\) \(string, error\)](<#IsJcbCreditCard>)
- [func IsLUHN\(value string\) \(string, error\)](<#IsLUHN>)
- [func IsLte\[T cmp.Ordered\]\(value, n T\) \(T, error\)](<#IsLte>)
- [func IsMAC\(value string\) \(string, error\)](<#IsMAC>)
- [func IsMasterCardCreditCard\(number string\) \(string, error\)](<#IsMasterCardCreditCard>)
- [func IsRegexp\(expression, value string\) \(string, error\)](<#IsRegexp>)
- [func IsTime\(params, value string\) \(string, error\)](<#IsTime>)
- [func IsURL\(value string\) \(string, error\)](<#IsURL>)
- [func IsUnionPayCreditCard\(number string\) \(string, error\)](<#IsUnionPayCreditCard>)
- [func IsVisaCreditCard\(number string\) \(string, error\)](<#IsVisaCreditCard>)
- [func Lower\(value string\) \(string, error\)](<#Lower>)
- [func ReflectCheckWithConfig\(value reflect.Value, config string\) \(reflect.Value, error\)](<#ReflectCheckWithConfig>)
- [func RegisterLocale\(locale string, messages map\[string\]string\)](<#RegisterLocale>)
- [func RegisterMaker\(name string, maker MakeCheckFunc\)](<#RegisterMaker>)
- [func Required\[T any\]\(value T\) \(T, error\)](<#Required>)
- [func Title\(value string\) \(string, error\)](<#Title>)
- [func TrimLeft\(value string\) \(string, error\)](<#TrimLeft>)
- [func TrimRight\(value string\) \(string, error\)](<#TrimRight>)
- [func TrimSpace\(value string\) \(string, error\)](<#TrimSpace>)
- [func URLEscape\(value string\) \(string, error\)](<#URLEscape>)
- [func URLUnescape\(value string\) \(string, error\)](<#URLUnescape>)
- [func Upper\(value string\) \(string, error\)](<#Upper>)
- [type CheckError](<#CheckError>)
- [func NewCheckError\(code string\) \*CheckError](<#NewCheckError>)
- [func NewCheckErrorWithData\(code string, data map\[string\]interface\{\}\) \*CheckError](<#NewCheckErrorWithData>)
- [func \(c \*CheckError\) Error\(\) string](<#CheckError.Error>)
- [func \(c \*CheckError\) ErrorWithLocale\(locale string\) string](<#CheckError.ErrorWithLocale>)
- [func \(c \*CheckError\) Is\(target error\) bool](<#CheckError.Is>)
- [type CheckFunc](<#CheckFunc>)
- [func MakeRegexpChecker\(expression string, invalidError error\) CheckFunc\[reflect.Value\]](<#MakeRegexpChecker>)
- [func MaxLen\[T any\]\(n int\) CheckFunc\[T\]](<#MaxLen>)
- [func MinLen\[T any\]\(n int\) CheckFunc\[T\]](<#MinLen>)
- [type MakeCheckFunc](<#MakeCheckFunc>)
## Constants
<a name="DefaultLocale"></a>
```go
const (
// DefaultLocale is the default locale.
DefaultLocale = locales.EnUS
)
```
## Variables
<a name="ErrGte"></a>
```go
var (
// ErrGte indicates that the value is not greater than or equal to the given value.
ErrGte = NewCheckError("NOT_GTE")
)
```
<a name="ErrLte"></a>
```go
var (
// ErrLte indicates that the value is not less than or equal to the given value.
ErrLte = NewCheckError("NOT_LTE")
)
```
<a name="ErrMaxLen"></a>
```go
var (
// ErrMaxLen indicates that the value's length is greater than the specified maximum.
ErrMaxLen = NewCheckError("NOT_MAX_LEN")
)
```
<a name="ErrMinLen"></a>
```go
var (
// ErrMinLen indicates that the value's length is less than the specified minimum.
ErrMinLen = NewCheckError("NOT_MIN_LEN")
)
```
<a name="ErrNotASCII"></a>
```go
var (
// ErrNotASCII indicates that the given string contains non-ASCII characters.
ErrNotASCII = NewCheckError("NOT_ASCII")
)
```
<a name="ErrNotAlphanumeric"></a>
```go
var (
// ErrNotAlphanumeric indicates that the given string contains non-alphanumeric characters.
ErrNotAlphanumeric = NewCheckError("NOT_ALPHANUMERIC")
)
```
<a name="ErrNotCIDR"></a>
```go
var (
// ErrNotCIDR indicates that the given value is not a valid CIDR.
ErrNotCIDR = NewCheckError("NOT_CIDR")
)
```
<a name="ErrNotCreditCard"></a>
```go
var (
// ErrNotCreditCard indicates that the given value is not a valid credit card number.
ErrNotCreditCard = NewCheckError("NOT_CREDIT_CARD")
)
```
<a name="ErrNotDigits"></a>
```go
var (
// ErrNotDigits indicates that the given value is not a valid digits string.
ErrNotDigits = NewCheckError("NOT_DIGITS")
)
```
<a name="ErrNotEmail"></a>
```go
var (
// ErrNotEmail indicates that the given value is not a valid email address.
ErrNotEmail = NewCheckError("NOT_EMAIL")
)
```
<a name="ErrNotFQDN"></a>
```go
var (
// ErrNotFQDN indicates that the given value is not a valid FQDN.
ErrNotFQDN = NewCheckError("FQDN")
)
```
<a name="ErrNotHex"></a>
```go
var (
// ErrNotHex indicates that the given string contains hex characters.
ErrNotHex = NewCheckError("NOT_HEX")
)
```
<a name="ErrNotIP"></a>
```go
var (
// ErrNotIP indicates that the given value is not a valid IP address.
ErrNotIP = NewCheckError("NOT_IP")
)
```
<a name="ErrNotIPv4"></a>
```go
var (
// ErrNotIPv4 indicates that the given value is not a valid IPv4 address.
ErrNotIPv4 = NewCheckError("NOT_IPV4")
)
```
<a name="ErrNotIPv6"></a>
```go
var (
// ErrNotIPv6 indicates that the given value is not a valid IPv6 address.
ErrNotIPv6 = NewCheckError("NOT_IPV6")
)
```
<a name="ErrNotISBN"></a>
```go
var (
// ErrNotISBN indicates that the given value is not a valid ISBN.
ErrNotISBN = NewCheckError("NOT_ISBN")
)
```
<a name="ErrNotLUHN"></a>
```go
var (
// ErrNotLUHN indicates that the given value is not a valid LUHN number.
ErrNotLUHN = NewCheckError("NOT_LUHN")
)
```
<a name="ErrNotMAC"></a>
```go
var (
// ErrNotMAC indicates that the given value is not a valid MAC address.
ErrNotMAC = NewCheckError("NOT_MAC")
)
```
<a name="ErrNotMatch"></a>ErrNotMatch indicates that the given string does not match the regexp pattern.
```go
var ErrNotMatch = NewCheckError("REGEXP")
```
<a name="ErrNotURL"></a>
```go
var (
// ErrNotURL indicates that the given value is not a valid URL.
ErrNotURL = NewCheckError("NOT_URL")
)
```
<a name="ErrRequired"></a>
```go
var (
// ErrRequired indicates that a required value was missing.
ErrRequired = NewCheckError("REQUIRED")
)
```
<a name="ErrTime"></a>
```go
var (
// ErrTime indicates that the value is not a valid based on the given time format.
ErrTime = NewCheckError("NOT_TIME")
)
```
<a name="Check"></a>
## func [Check](<https://github.com/cinar/checker/blob/main/checker.go#L32>)
```go
func Check[T any](value T, checks ...CheckFunc[T]) (T, error)
```
Check applies the given check functions to a value sequentially. It returns the final value and the first encountered error, if any.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
name := " Onur Cinar "
name, err := v2.Check(name, v2.TrimSpace, v2.Required)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(name)
}
```
#### Output
```
Onur Cinar
```
</p>
</details>
<a name="CheckStruct"></a>
## func [CheckStruct](<https://github.com/cinar/checker/blob/main/checker.go#L62>)
```go
func CheckStruct(st any) (map[string]error, bool)
```
CheckStruct checks the given struct based on the validation rules specified in the "checker" tag of each struct field. It returns a map of field names to their corresponding errors, and a boolean indicating if all checks passed.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
type Person struct {
Name string `checkers:"trim required"`
}
person := &Person{
Name: " Onur Cinar ",
}
errs, ok := v2.CheckStruct(person)
if !ok {
fmt.Println(errs)
return
}
fmt.Println(person.Name)
}
```
#### Output
```
Onur Cinar
```
</p>
</details>
<a name="CheckWithConfig"></a>
## func [CheckWithConfig](<https://github.com/cinar/checker/blob/main/checker.go#L47>)
```go
func CheckWithConfig[T any](value T, config string) (T, error)
```
CheckWithConfig applies the check functions specified by the config string to the given value. It returns the modified value and the first encountered error, if any.
<a name="HTMLEscape"></a>
## func [HTMLEscape](<https://github.com/cinar/checker/blob/main/html_escape.go#L19>)
```go
func HTMLEscape(value string) (string, error)
```
HTMLEscape applies HTML escaping to special characters.
<a name="HTMLUnescape"></a>
## func [HTMLUnescape](<https://github.com/cinar/checker/blob/main/html_unescape.go#L17>)
```go
func HTMLUnescape(value string) (string, error)
```
HTMLUnescape applies HTML unescaping to special characters.
<a name="IsASCII"></a>
## func [IsASCII](<https://github.com/cinar/checker/blob/main/ascii.go#L24>)
```go
func IsASCII(value string) (string, error)
```
IsASCII checks if the given string consists of only ASCII characters.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsASCII("Checker")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsAlphanumeric"></a>
## func [IsAlphanumeric](<https://github.com/cinar/checker/blob/main/alphanumeric.go#L24>)
```go
func IsAlphanumeric(value string) (string, error)
```
IsAlphanumeric checks if the given string consists of only alphanumeric characters.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsAlphanumeric("ABcd1234")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsAmexCreditCard"></a>
## func [IsAmexCreditCard](<https://github.com/cinar/checker/blob/main/credit_card.go#L80>)
```go
func IsAmexCreditCard(number string) (string, error)
```
IsAmexCreditCard checks if the given valie is a valid AMEX credit card.
<details><summary>Example</summary>
<p>
```go
package main
import (
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsAmexCreditCard("378282246310005")
if err != nil {
// Send the errors back to the user
}
}
```
</p>
</details>
<a name="IsAnyCreditCard"></a>
## func [IsAnyCreditCard](<https://github.com/cinar/checker/blob/main/credit_card.go#L75>)
```go
func IsAnyCreditCard(number string) (string, error)
```
IsAnyCreditCard checks if the given value is a valid credit card number.
<details><summary>Example</summary>
<p>
```go
package main
import (
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsAnyCreditCard("6011111111111117")
if err != nil {
// Send the errors back to the user
}
}
```
</p>
</details>
<a name="IsCIDR"></a>
## func [IsCIDR](<https://github.com/cinar/checker/blob/main/cidr.go#L24>)
```go
func IsCIDR(value string) (string, error)
```
IsCIDR checks if the value is a valid CIDR notation IP address and prefix length.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsCIDR("2001:db8::/32")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsDigits"></a>
## func [IsDigits](<https://github.com/cinar/checker/blob/main/digits.go#L24>)
```go
func IsDigits(value string) (string, error)
```
IsDigits checks if the value contains only digit characters.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsDigits("123456")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsDinersCreditCard"></a>
## func [IsDinersCreditCard](<https://github.com/cinar/checker/blob/main/credit_card.go#L85>)
```go
func IsDinersCreditCard(number string) (string, error)
```
IsDinersCreditCard checks if the given valie is a valid Diners credit card.
<details><summary>Example</summary>
<p>
```go
package main
import (
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsDinersCreditCard("36227206271667")
if err != nil {
// Send the errors back to the user
}
}
```
</p>
</details>
<a name="IsDiscoverCreditCard"></a>
## func [IsDiscoverCreditCard](<https://github.com/cinar/checker/blob/main/credit_card.go#L90>)
```go
func IsDiscoverCreditCard(number string) (string, error)
```
IsDiscoverCreditCard checks if the given valie is a valid Discover credit card.
<details><summary>Example</summary>
<p>
```go
package main
import (
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsDiscoverCreditCard("6011111111111117")
if err != nil {
// Send the errors back to the user
}
}
```
</p>
</details>
<a name="IsEmail"></a>
## func [IsEmail](<https://github.com/cinar/checker/blob/main/email.go#L24>)
```go
func IsEmail(value string) (string, error)
```
IsEmail checks if the value is a valid email address.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsEmail("test@example.com")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsFQDN"></a>
## func [IsFQDN](<https://github.com/cinar/checker/blob/main/fqdn.go#L27>)
```go
func IsFQDN(value string) (string, error)
```
IsFQDN checks if the value is a valid fully qualified domain name \(FQDN\).
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsFQDN("example.com")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsGte"></a>
## func [IsGte](<https://github.com/cinar/checker/blob/main/gte.go#L25>)
```go
func IsGte[T cmp.Ordered](value, n T) (T, error)
```
IsGte checks if the value is greater than or equal to the given value.
<a name="IsHex"></a>
## func [IsHex](<https://github.com/cinar/checker/blob/main/hex.go#L23>)
```go
func IsHex(value string) (string, error)
```
IsHex checks if the given string consists of only hex characters.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsHex("0123456789abcdefABCDEF")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsIP"></a>
## func [IsIP](<https://github.com/cinar/checker/blob/main/ip.go#L24>)
```go
func IsIP(value string) (string, error)
```
IsIP checks if the value is a valid IP address.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsIP("192.168.1.1")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsIPv4"></a>
## func [IsIPv4](<https://github.com/cinar/checker/blob/main/ipv4.go#L24>)
```go
func IsIPv4(value string) (string, error)
```
IsIPv4 checks if the value is a valid IPv4 address.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsIPv4("192.168.1.1")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsIPv6"></a>
## func [IsIPv6](<https://github.com/cinar/checker/blob/main/ipv6.go#L24>)
```go
func IsIPv6(value string) (string, error)
```
IsIPv6 checks if the value is a valid IPv6 address.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsIPv6("2001:db8::1")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsISBN"></a>
## func [IsISBN](<https://github.com/cinar/checker/blob/main/isbn.go#L27>)
```go
func IsISBN(value string) (string, error)
```
IsISBN checks if the value is a valid ISBN\-10 or ISBN\-13.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsISBN("1430248270")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsJcbCreditCard"></a>
## func [IsJcbCreditCard](<https://github.com/cinar/checker/blob/main/credit_card.go#L95>)
```go
func IsJcbCreditCard(number string) (string, error)
```
IsJcbCreditCard checks if the given valie is a valid JCB 15 credit card.
<details><summary>Example</summary>
<p>
```go
package main
import (
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsJcbCreditCard("3530111333300000")
if err != nil {
// Send the errors back to the user
}
}
```
</p>
</details>
<a name="IsLUHN"></a>
## func [IsLUHN](<https://github.com/cinar/checker/blob/main/luhn.go#L24>)
```go
func IsLUHN(value string) (string, error)
```
IsLUHN checks if the value is a valid LUHN number.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsLUHN("4012888888881881")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsLte"></a>
## func [IsLte](<https://github.com/cinar/checker/blob/main/lte.go#L25>)
```go
func IsLte[T cmp.Ordered](value, n T) (T, error)
```
IsLte checks if the value is less than or equal to the given value.
<a name="IsMAC"></a>
## func [IsMAC](<https://github.com/cinar/checker/blob/main/mac.go#L24>)
```go
func IsMAC(value string) (string, error)
```
IsMAC checks if the value is a valid MAC address.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsMAC("00:1A:2B:3C:4D:5E")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsMasterCardCreditCard"></a>
## func [IsMasterCardCreditCard](<https://github.com/cinar/checker/blob/main/credit_card.go#L100>)
```go
func IsMasterCardCreditCard(number string) (string, error)
```
IsMasterCardCreditCard checks if the given valie is a valid MasterCard credit card.
<details><summary>Example</summary>
<p>
```go
package main
import (
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsMasterCardCreditCard("5555555555554444")
if err != nil {
// Send the errors back to the user
}
}
```
</p>
</details>
<a name="IsRegexp"></a>
## func [IsRegexp](<https://github.com/cinar/checker/blob/main/regexp.go#L20>)
```go
func IsRegexp(expression, value string) (string, error)
```
IsRegexp checks if the given string matches the given regexp expression.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsRegexp("^[0-9a-fA-F]+$", "ABcd1234")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsTime"></a>
## func [IsTime](<https://github.com/cinar/checker/blob/main/time.go#L47>)
```go
func IsTime(params, value string) (string, error)
```
IsTime checks if the given value is a valid time based on the given layout.
<details><summary>Example</summary>
<p>
```go
package main
import (
v2 "github.com/cinar/checker/v2"
)
func main() {
value := "2024-12-31"
_, err := v2.IsTime("DateOnly", value)
if err != nil {
panic(err)
}
}
```
</p>
</details>
<details><summary>Example (Custom)</summary>
<p>
```go
package main
import (
v2 "github.com/cinar/checker/v2"
)
func main() {
rfc3339Layout := "2006-01-02T15:04:05Z07:00"
value := "2024-12-31T10:20:00Z07:00"
_, err := v2.IsTime(rfc3339Layout, value)
if err != nil {
panic(err)
}
}
```
</p>
</details>
<a name="IsURL"></a>
## func [IsURL](<https://github.com/cinar/checker/blob/main/url.go#L24>)
```go
func IsURL(value string) (string, error)
```
IsURL checks if the value is a valid URL.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsURL("https://example.com")
if err != nil {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="IsUnionPayCreditCard"></a>
## func [IsUnionPayCreditCard](<https://github.com/cinar/checker/blob/main/credit_card.go#L105>)
```go
func IsUnionPayCreditCard(number string) (string, error)
```
IsUnionPayCreditCard checks if the given valie is a valid UnionPay credit card.
<details><summary>Example</summary>
<p>
```go
package main
import (
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsUnionPayCreditCard("6200000000000005")
if err != nil {
// Send the errors back to the user
}
}
```
</p>
</details>
<a name="IsVisaCreditCard"></a>
## func [IsVisaCreditCard](<https://github.com/cinar/checker/blob/main/credit_card.go#L110>)
```go
func IsVisaCreditCard(number string) (string, error)
```
IsVisaCreditCard checks if the given valie is a valid Visa credit card.
<details><summary>Example</summary>
<p>
```go
package main
import (
v2 "github.com/cinar/checker/v2"
)
func main() {
_, err := v2.IsVisaCreditCard("4111111111111111")
if err != nil {
// Send the errors back to the user
}
}
```
</p>
</details>
<a name="Lower"></a>
## func [Lower](<https://github.com/cinar/checker/blob/main/lower.go#L19>)
```go
func Lower(value string) (string, error)
```
Lower maps all Unicode letters in the given value to their lower case.
<a name="ReflectCheckWithConfig"></a>
## func [ReflectCheckWithConfig](<https://github.com/cinar/checker/blob/main/checker.go#L55>)
```go
func ReflectCheckWithConfig(value reflect.Value, config string) (reflect.Value, error)
```
ReflectCheckWithConfig applies the check functions specified by the config string to the given reflect.Value. It returns the modified reflect.Value and the first encountered error, if any.
<a name="RegisterLocale"></a>
## func [RegisterLocale](<https://github.com/cinar/checker/blob/main/check_error.go#L80>)
```go
func RegisterLocale(locale string, messages map[string]string)
```
RegisterLocale registers the localized error messages for the given locale.
<a name="RegisterMaker"></a>
## func [RegisterMaker](<https://github.com/cinar/checker/blob/main/maker.go#L54>)
```go
func RegisterMaker(name string, maker MakeCheckFunc)
```
RegisterMaker registers a new maker function with the given name.
<details><summary>Example</summary>
<p>
```go
package main
import (
"fmt"
"reflect"
"github.com/cinar/checker/v2/locales"
v2 "github.com/cinar/checker/v2"
)
func main() {
locales.EnUSMessages["NOT_FRUIT"] = "Not a fruit name."
v2.RegisterMaker("is-fruit", func(params string) v2.CheckFunc[reflect.Value] {
return func(value reflect.Value) (reflect.Value, error) {
stringValue := value.Interface().(string)
if stringValue == "apple" || stringValue == "banana" {
return value, nil
}
return value, v2.NewCheckError("NOT_FRUIT")
}
})
type Item struct {
Name string `checkers:"is-fruit"`
}
person := &Item{
Name: "banana",
}
err, ok := v2.CheckStruct(person)
if !ok {
fmt.Println(err)
}
}
```
</p>
</details>
<a name="Required"></a>
## func [Required](<https://github.com/cinar/checker/blob/main/required.go#L22>)
```go
func Required[T any](value T) (T, error)
```
Required checks if the given value of type T is its zero value. It returns an error if the value is zero.
<a name="Title"></a>
## func [Title](<https://github.com/cinar/checker/blob/main/title.go#L20>)
```go
func Title(value string) (string, error)
```
Title returns the value of the string with the first letter of each word in upper case.
<a name="TrimLeft"></a>
## func [TrimLeft](<https://github.com/cinar/checker/blob/main/trim_left.go#L19>)
```go
func TrimLeft(value string) (string, error)
```
TrimLeft returns the value of the string with whitespace removed from the beginning.
<a name="TrimRight"></a>
## func [TrimRight](<https://github.com/cinar/checker/blob/main/trim_right.go#L19>)
```go
func TrimRight(value string) (string, error)
```
TrimRight returns the value of the string with whitespace removed from the end.
<a name="TrimSpace"></a>
## func [TrimSpace](<https://github.com/cinar/checker/blob/main/trim_space.go#L19>)
```go
func TrimSpace(value string) (string, error)
```
TrimSpace returns the value of the string with whitespace removed from both ends.
<a name="URLEscape"></a>
## func [URLEscape](<https://github.com/cinar/checker/blob/main/url_escape.go#L17>)
```go
func URLEscape(value string) (string, error)
```
URLEscape applies URL escaping to special characters.
<a name="URLUnescape"></a>
## func [URLUnescape](<https://github.com/cinar/checker/blob/main/url_unescape.go#L17>)
```go
func URLUnescape(value string) (string, error)
```
URLUnescape applies URL unescaping to special characters.
<a name="Upper"></a>
## func [Upper](<https://github.com/cinar/checker/blob/main/upper.go#L19>)
```go
func Upper(value string) (string, error)
```
Upper maps all Unicode letters in the given value to their upper case.
<a name="CheckError"></a>
## type [CheckError](<https://github.com/cinar/checker/blob/main/check_error.go#L16-L22>)
CheckError defines the check error.
```go
type CheckError struct {
// Code is the error code.
Code string
// data is the error data.
Data map[string]interface{}
}
```
<a name="NewCheckError"></a>
### func [NewCheckError](<https://github.com/cinar/checker/blob/main/check_error.go#L35>)
```go
func NewCheckError(code string) *CheckError
```
NewCheckError creates a new check error with the given code.
<a name="NewCheckErrorWithData"></a>
### func [NewCheckErrorWithData](<https://github.com/cinar/checker/blob/main/check_error.go#L43>)
```go
func NewCheckErrorWithData(code string, data map[string]interface{}) *CheckError
```
NewCheckErrorWithData creates a new check error with the given code and data.
<a name="CheckError.Error"></a>
### func \(\*CheckError\) [Error](<https://github.com/cinar/checker/blob/main/check_error.go#L51>)
```go
func (c *CheckError) Error() string
```
Error returns the error message for the check.
<a name="CheckError.ErrorWithLocale"></a>
### func \(\*CheckError\) [ErrorWithLocale](<https://github.com/cinar/checker/blob/main/check_error.go#L65>)
```go
func (c *CheckError) ErrorWithLocale(locale string) string
```
ErrorWithLocale returns the localized error message for the check with the given locale.
<a name="CheckError.Is"></a>
### func \(\*CheckError\) [Is](<https://github.com/cinar/checker/blob/main/check_error.go#L56>)
```go
func (c *CheckError) Is(target error) bool
```
Is reports whether the check error is the same as the target error.
<a name="CheckFunc"></a>
## type [CheckFunc](<https://github.com/cinar/checker/blob/main/check_func.go#L11>)
CheckFunc is a function that takes a value of type T and performs a check on it. It returns the resulting value and any error that occurred during the check.
```go
type CheckFunc[T any] func(value T) (T, error)
```
<a name="MakeRegexpChecker"></a>
### func [MakeRegexpChecker](<https://github.com/cinar/checker/blob/main/regexp.go#L29>)
```go
func MakeRegexpChecker(expression string, invalidError error) CheckFunc[reflect.Value]
```
MakeRegexpChecker makes a regexp checker for the given regexp expression with the given invalid result.
<a name="MaxLen"></a>
### func [MaxLen](<https://github.com/cinar/checker/blob/main/max_len.go#L25>)
```go
func MaxLen[T any](n int) CheckFunc[T]
```
MaxLen checks if the length of the given value \(string, slice, or map\) is at most n. Returns an error if the length is greater than n.
<a name="MinLen"></a>
### func [MinLen](<https://github.com/cinar/checker/blob/main/min_len.go#L25>)
```go
func MinLen[T any](n int) CheckFunc[T]
```
MinLen checks if the length of the given value \(string, slice, or map\) is at least n. Returns an error if the length is less than n.
<a name="MakeCheckFunc"></a>
## type [MakeCheckFunc](<https://github.com/cinar/checker/blob/main/maker.go#L15>)
MakeCheckFunc is a function that returns a check function using the given params.
```go
type MakeCheckFunc func(params string) CheckFunc[reflect.Value]
```
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
<!-- gomarkdoc:embed:end -->