Documentation ¶
Overview ¶
Example (Email) ¶
package main import ( "fmt" v "github.com/RussellLuo/validating/v3" "github.com/RussellLuo/vext" ) func main() { value := "foo#example.com" if err := v.Validate(v.Value(value, vext.Email())); err != nil { fmt.Printf("err: %v\n", err) } }
Output: err: INVALID(invalid email)
Example (Hash) ¶
package main import ( "fmt" v "github.com/RussellLuo/validating/v3" "github.com/RussellLuo/vext" ) func main() { value := "5d41402abc4b2a76b9719d911017c59" // 31 characters (one less than MD5) if err := v.Validate(v.Value(value, vext.Hash("md5"))); err != nil { fmt.Printf("err: %v\n", err) } }
Output: err: INVALID(invalid md5 hash)
Example (Ip) ¶
package main import ( "fmt" v "github.com/RussellLuo/validating/v3" "github.com/RussellLuo/vext" ) func main() { value := "127.0.0." if err := v.Validate(v.Value(value, vext.IP())); err != nil { fmt.Printf("err: %v\n", err) } }
Output: err: INVALID(invalid IP)
Example (Isbn) ¶
package main import ( "fmt" v "github.com/RussellLuo/validating/v3" "github.com/RussellLuo/vext" ) func main() { value := "" if err := v.Validate(v.Value(value, vext.ISBN(10))); err != nil { fmt.Printf("err: %v\n", err) } }
Output: err: INVALID(invalid ISBN 10)
Example (Time) ¶
package main import ( "fmt" "time" v "github.com/RussellLuo/validating/v3" "github.com/RussellLuo/vext" ) func main() { value := "2006-01-02T15:04:05" // missing timezone if err := v.Validate(v.Value(value, vext.Time(time.RFC3339))); err != nil { fmt.Printf("err: %v\n", err) } }
Output: err: INVALID(invalid time)
Index ¶
- func ASCII() *v.MessageValidator
- func Alpha() *v.MessageValidator
- func Alphanumeric() *v.MessageValidator
- func Base64() *v.MessageValidator
- func CIDR() *v.MessageValidator
- func CreditCard() *v.MessageValidator
- func DNSName() *v.MessageValidator
- func DataURI() *v.MessageValidator
- func DialString() *v.MessageValidator
- func Email() *v.MessageValidator
- func EmailNonDisposable() *v.MessageValidator
- func Hash(algorithm string) *v.MessageValidator
- func HexColor() *v.MessageValidator
- func HexNumber() *v.MessageValidator
- func IP() *v.MessageValidator
- func IPv4() *v.MessageValidator
- func IPv6() *v.MessageValidator
- func ISBN(version int) *v.MessageValidator
- func ISO3166Alpha2() *v.MessageValidator
- func ISO3166Alpha3() *v.MessageValidator
- func ISO4217() *v.MessageValidator
- func ISO693Alpha2() *v.MessageValidator
- func ISO693Alpha3b() *v.MessageValidator
- func Latitude() *v.MessageValidator
- func Longitude() *v.MessageValidator
- func MAC() *v.MessageValidator
- func MagnetURI() *v.MessageValidator
- func MongoID() *v.MessageValidator
- func RGBColor() *v.MessageValidator
- func SSN() *v.MessageValidator
- func Time(layout string) (mv *v.MessageValidator)
- func URL() *v.MessageValidator
- func UUID() *v.MessageValidator
- func UUIDv3() *v.MessageValidator
- func UUIDv4() *v.MessageValidator
- func UUIDv5() *v.MessageValidator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ASCII ¶
func ASCII() *v.MessageValidator
ASCII is a leaf validator factory used to create a validator, which will succeed when the field's value contains only ASCII chars.
func Alpha ¶
func Alpha() *v.MessageValidator
Alpha is a leaf validator factory used to create a validator, which will succeed when the field's value contains only ASCII letters (a-zA-Z).
func Alphanumeric ¶
func Alphanumeric() *v.MessageValidator
Alphanumeric is a leaf validator factory used to create a validator, which will succeed when the field's value contains only letters and numbers.
func Base64 ¶
func Base64() *v.MessageValidator
Base64 is a leaf validator factory used to create a validator, which will succeed when the field's value is a base64 encoded string.
func CIDR ¶
func CIDR() *v.MessageValidator
CIDR is a leaf validator factory used to create a validator, which will succeed when the field's value is an valid CIDR notation (IPV4 & IPV6).
func CreditCard ¶
func CreditCard() *v.MessageValidator
CreditCard is a leaf validator factory used to create a validator, which will succeed when the field's value is a credit card.
func DNSName ¶
func DNSName() *v.MessageValidator
DNSName is a leaf validator factory used to create a validator, which will succeed when the field's value is a DNS name.
func DataURI ¶
func DataURI() *v.MessageValidator
DataURI is a leaf validator factory used to create a validator, which will succeed when the field's value is a base64 encoded data URI such as an image.
func DialString ¶
func DialString() *v.MessageValidator
DialString is a leaf validator factory used to create a validator, which will succeed when the field's value is a dial string.
func Email ¶
func Email() *v.MessageValidator
Email is a leaf validator factory used to create a validator, which will succeed when the field's value is an email.
func EmailNonDisposable ¶
func EmailNonDisposable() *v.MessageValidator
EmailNonDisposable is a leaf validator factory used to create a validator, which will succeed when the field's value is a non-disposable email address. It uses the `is-email-disposable` package to check if the email domain is disposable.
func Hash ¶
func Hash(algorithm string) *v.MessageValidator
Hash is a leaf validator factory used to create a validator, which will succeed when the field's value is a hash of type algorithm.
Supported algorithms: - md4 - md5 - sha1 - sha256 - sha384 - sha512 - ripemd128 - ripemd160 - tiger128 - tiger160 - tiger192 - crc32 - crc32b
func HexColor ¶
func HexColor() *v.MessageValidator
HexColor is a leaf validator factory used to create a validator, which will succeed when the field's value is a hexadecimal color.
func HexNumber ¶
func HexNumber() *v.MessageValidator
HexNumber is a leaf validator factory used to create a validator, which will succeed when the field's value is a hexadecimal number.
func IP ¶
func IP() *v.MessageValidator
IP is a leaf validator factory used to create a validator, which will succeed when the field's value is an IPv4 or IPv6 string.
func IPv4 ¶
func IPv4() *v.MessageValidator
IPv4 is a leaf validator factory used to create a validator, which will succeed when the field's value is an IPv4 string.
func IPv6 ¶
func IPv6() *v.MessageValidator
IPv6 is a leaf validator factory used to create a validator, which will succeed when the field's value is an IPv6 string.
func ISBN ¶
func ISBN(version int) *v.MessageValidator
ISBN is a leaf validator factory used to create a validator, which will succeed when the field's value is an ISBN (version 10 or 13) string.
func ISO3166Alpha2 ¶
func ISO3166Alpha2() *v.MessageValidator
ISO3166Alpha2 is a leaf validator factory used to create a validator, which will succeed when the field's value is a two-letter country code.
func ISO3166Alpha3 ¶
func ISO3166Alpha3() *v.MessageValidator
ISO3166Alpha3 is a leaf validator factory used to create a validator, which will succeed when the field's value is a three-letter country code.
func ISO4217 ¶
func ISO4217() *v.MessageValidator
ISO4217 is a leaf validator factory used to create a validator, which will succeed when the field's value is an ISO currency code.
func ISO693Alpha2 ¶
func ISO693Alpha2() *v.MessageValidator
ISO693Alpha2 is a leaf validator factory used to create a validator, which will succeed when the field's value is a two-letter language code.
func ISO693Alpha3b ¶
func ISO693Alpha3b() *v.MessageValidator
ISO693Alpha3 is a leaf validator factory used to create a validator, which will succeed when the field's value is a three-letter language code.
func Latitude ¶
func Latitude() *v.MessageValidator
Latitude is a leaf validator factory used to create a validator, which will succeed when the field's value is a latitude.
func Longitude ¶
func Longitude() *v.MessageValidator
Longitude is a leaf validator factory used to create a validator, which will succeed when the field's value is a longitude.
func MAC ¶
func MAC() *v.MessageValidator
MAC is a leaf validator factory used to create a validator, which will succeed when the field's value is a MAC address.
func MagnetURI ¶
func MagnetURI() *v.MessageValidator
MagnetURI is a leaf validator factory used to create a validator, which will succeed when the field's value is a magnet URI.
func MongoID ¶
func MongoID() *v.MessageValidator
MongoID is a leaf validator factory used to create a validator, which will succeed when the field's value is a hex-encoded representation of a MongoDB ObjectId.
func RGBColor ¶
func RGBColor() *v.MessageValidator
RGBColor is a leaf validator factory used to create a validator, which will succeed when the field's value is a RGB color in form rgb(RRR, GGG, BBB).
func SSN ¶
func SSN() *v.MessageValidator
SSN is a leaf validator factory used to create a validator, which will succeed when the field's value is a U.S. Social Security Number.
func Time ¶
func Time(layout string) (mv *v.MessageValidator)
Time is a leaf validator factory used to create a validator, which will succeed when the field's value matches the given time format specified by layout.
func URL ¶
func URL() *v.MessageValidator
URL is a leaf validator factory used to create a validator, which will succeed when the field's value is an URL.
func UUID ¶
func UUID() *v.MessageValidator
UUID is a leaf validator factory used to create a validator, which will succeed when the field's value is an UUID (version 3, 4 or 5) string.
func UUIDv3 ¶
func UUIDv3() *v.MessageValidator
UUID is a leaf validator factory used to create a validator, which will succeed when the field's value is an UUID version 3 string.
func UUIDv4 ¶
func UUIDv4() *v.MessageValidator
UUID is a leaf validator factory used to create a validator, which will succeed when the field's value is an UUID version 4 string.
func UUIDv5 ¶
func UUIDv5() *v.MessageValidator
UUID is a leaf validator factory used to create a validator, which will succeed when the field's value is an UUID version 5 string.
Types ¶
This section is empty.