vext

package module
v0.0.0-...-39e98c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 7 Imported by: 2

README

vext

Extension validator factories for validating.

Currently supported:

Installation

$ go get github.com/RussellLuo/vext@latest

Documentation

Check out the Godoc.

License

MIT

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL