validate

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(value float64) float64

Abs returns absolute value of number

func ByteLength

func ByteLength(str string, params ...string) bool

ByteLength checks string's length

func HasLowerCase

func HasLowerCase(str string) bool

HasLowerCase checks if the string contains at least 1 lowercase. Empty string is valid.

func HasUpperCase

func HasUpperCase(str string) bool

HasUpperCase checks if the string contains as least 1 uppercase. Empty string is valid.

func HasWhitespace

func HasWhitespace(str string) bool

HasWhitespace checks if the string contains any whitespace

func HasWhitespaceOnly

func HasWhitespaceOnly(str string) bool

HasWhitespaceOnly checks the string only contains whitespace

func InRange

func InRange(value, left, right any) bool

InRange returns true if value lies between left and right border, generic type to handle int, float32, float64 and string. All types must the same type. False if value doesn't lie in range or if it incompatible or not comparable

func IsASCII

func IsASCII(str string) bool

IsASCII checks if the string contains ASCII chars only. Empty string is valid.

func IsAlpha

func IsAlpha(str string) bool

IsAlpha checks if the string contains only letters (a-zA-Z). Empty string is valid.

func IsAlphanumeric

func IsAlphanumeric(str string) bool

IsAlphanumeric checks if the string contains only letters and numbers. Empty string is valid.

func IsBase64

func IsBase64(str string) bool

IsBase64 checks if a string is base64 encoded.

func IsByteLength

func IsByteLength(str string, min, max int) bool

IsByteLength checks if the string's length (in bytes) falls in a range.

func IsCIDR

func IsCIDR(str string) bool

IsCIDR checks if the string is an valid CIDR notiation (IPV4 & IPV6)

func IsCRC32

func IsCRC32(str string) bool

IsCRC32 checks is a string is a CRC32 hash. Alias for `IsHash(str, "crc32")`

func IsCRC32b

func IsCRC32b(str string) bool

IsCRC32b checks is a string is a CRC32b hash. Alias for `IsHash(str, "crc32b")`

func IsCreditCard

func IsCreditCard(str string) bool

IsCreditCard checks if the string is a credit card.

func IsDNSName

func IsDNSName(str string) bool

IsDNSName will validate the given string as a DNS name

func IsDataURI

func IsDataURI(str string) bool

IsDataURI checks if a string is base64 encoded data URI such as an image

func IsDialString

func IsDialString(str string) bool

IsDialString validates the given string for usage with the various Dial() functions

func IsDivisibleBy

func IsDivisibleBy(str, num string) bool

IsDivisibleBy checks if the string is a number that's divisible by another. If second argument is not valid integer or zero, it's return false. Otherwise, if first argument is not valid integer or zero, it's return true (Invalid string converts to zero).

func IsE164

func IsE164(str string) bool

func IsEmail

func IsEmail(str string) bool

IsEmail checks if the string is an email.

func IsExistingEmail

func IsExistingEmail(email string) bool

IsExistingEmail checks if the string is an email of existing domain

func IsFloat

func IsFloat(str string) bool

IsFloat checks if the string is a float.

func IsHash

func IsHash(str string, algorithm string) bool

IsHash checks if a string is a hash of type algorithm. Algorithm is one of ['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']

func IsHexadecimal

func IsHexadecimal(str string) bool

IsHexadecimal checks if the string is a hexadecimal number.

func IsHexcolor

func IsHexcolor(str string) bool

IsHexcolor checks if the string is a hexadecimal color.

func IsHost

func IsHost(str string) bool

IsHost checks if the string is a valid IP (both v4 and v6) or a valid DNS name

func IsIMEI

func IsIMEI(str string) bool

IsIMEI checks if a string is valid IMEI

func IsIMSI

func IsIMSI(str string) bool

IsIMSI checks if a string is valid IMSI

func IsIP

func IsIP(str string) bool

IsIP checks if a string is either IP version 4 or 6. Alias for `net.ParseIP`

func IsIPv4

func IsIPv4(str string) bool

IsIPv4 checks if the string is an IP version 4.

func IsIPv6

func IsIPv6(str string) bool

IsIPv6 checks if the string is an IP version 6.

func IsISO3166Alpha2

func IsISO3166Alpha2(str string) bool

IsISO3166Alpha2 checks if a string is valid two-letter country code

func IsISO3166Alpha3

func IsISO3166Alpha3(str string) bool

IsISO3166Alpha3 checks if a string is valid three-letter country code

func IsISO4217

func IsISO4217(str string) bool

IsISO4217 checks if string is valid ISO currency code

func IsISO693Alpha2

func IsISO693Alpha2(str string) bool

IsISO693Alpha2 checks if a string is valid two-letter language code

func IsISO693Alpha3b

func IsISO693Alpha3b(str string) bool

IsISO693Alpha3b checks if a string is valid three-letter language code

func IsIn

func IsIn(str string, params ...string) bool

IsIn checks if string str is a member of the set of strings params

func IsInRaw

func IsInRaw(str string, params ...string) bool

IsInRaw checks if string is in list of allowed values

func IsInt

func IsInt(str string) bool

IsInt checks if the string is an integer. Empty string is valid.

func IsJSON

func IsJSON(str string) bool

IsJSON checks if the string is valid JSON (note: uses json.Unmarshal).

func IsLatitude

func IsLatitude(str string) bool

IsLatitude checks if a string is valid latitude.

func IsLongitude

func IsLongitude(str string) bool

IsLongitude checks if a string is valid longitude.

func IsLowerCase

func IsLowerCase(str string) bool

IsLowerCase checks if the string is lowercase. Empty string is valid.

func IsMAC

func IsMAC(str string) bool

IsMAC checks if a string is valid MAC address. Possible MAC formats: 01:23:45:67:89:ab 01:23:45:67:89:ab:cd:ef 01-23-45-67-89-ab 01-23-45-67-89-ab-cd-ef 0123.4567.89ab 0123.4567.89ab.cdef

func IsMD4

func IsMD4(str string) bool

IsMD4 checks is a string is a MD4 hash. Alias for `IsHash(str, "md4")`

func IsMD5

func IsMD5(str string) bool

IsMD5 checks is a string is a MD5 hash. Alias for `IsHash(str, "md5")`

func IsMongoID

func IsMongoID(str string) bool

IsMongoID checks if the string is a valid hex-encoded representation of a MongoDB ObjectId.

func IsMultibyte

func IsMultibyte(str string) bool

IsMultibyte checks if the string contains one or more multibyte chars. Empty string is valid.

func IsNatural

func IsNatural(value float64) bool

IsNatural returns true if value is natural number (positive and whole)

func IsNegative

func IsNegative(value float64) bool

IsNegative returns true if value < 0

func IsNonNegative

func IsNonNegative(value float64) bool

IsNonNegative returns true if value >= 0

func IsNonPositive

func IsNonPositive(value float64) bool

IsNonPositive returns true if value <= 0

func IsNotNull

func IsNotNull(str string) bool

IsNotNull checks if the string is not null.

func IsNull

func IsNull(str string) bool

IsNull checks if the string is null.

func IsNumeric

func IsNumeric(str string) bool

IsNumeric checks if the string contains only numbers. Empty string is valid.

func IsPort

func IsPort(str string) bool

IsPort checks if a string represents a valid port

func IsPositive

func IsPositive(value float64) bool

IsPositive returns true if value > 0

func IsPrintableASCII

func IsPrintableASCII(str string) bool

IsPrintableASCII checks if the string contains printable ASCII chars only. Empty string is valid.

func IsRFC3339

func IsRFC3339(str string) bool

IsRFC3339 checks if string is valid timestamp value according to RFC3339

func IsRFC3339WithoutZone

func IsRFC3339WithoutZone(str string) bool

IsRFC3339WithoutZone checks if string is valid timestamp value according to RFC3339 which excludes the timezone.

func IsRGBcolor

func IsRGBcolor(str string) bool

IsRGBcolor checks if the string is a valid RGB color in form rgb(RRR, GGG, BBB).

func IsRegex

func IsRegex(str string) bool

IsRegex checks if a give string is a valid regex with RE2 syntax or not

func IsRequestURI

func IsRequestURI(rawurl string) bool

IsRequestURI checks if the string rawurl, assuming it was received in an HTTP request, is an absolute URI or an absolute path.

func IsRequestURL

func IsRequestURL(rawurl string) bool

IsRequestURL checks if the string rawurl, assuming it was received in an HTTP request, is a valid URL confirm to RFC 3986

func IsRipeMD128

func IsRipeMD128(str string) bool

IsRipeMD128 checks is a string is a RipeMD128 hash. Alias for `IsHash(str, "ripemd128")`

func IsRipeMD160

func IsRipeMD160(str string) bool

IsRipeMD160 checks is a string is a RipeMD160 hash. Alias for `IsHash(str, "ripemd160")`

func IsSHA1

func IsSHA1(str string) bool

IsSHA1 checks is a string is a SHA-1 hash. Alias for `IsHash(str, "sha1")`

func IsSHA256

func IsSHA256(str string) bool

IsSHA256 checks is a string is a SHA256 hash. Alias for `IsHash(str, "sha256")`

func IsSHA3224

func IsSHA3224(str string) bool

IsSHA3224 checks is a string is a SHA3-224 hash. Alias for `IsHash(str, "sha3-224")`

func IsSHA3256

func IsSHA3256(str string) bool

IsSHA3256 checks is a string is a SHA3-256 hash. Alias for `IsHash(str, "sha3-256")`

func IsSHA3384

func IsSHA3384(str string) bool

IsSHA3384 checks is a string is a SHA3-384 hash. Alias for `IsHash(str, "sha3-384")`

func IsSHA3512

func IsSHA3512(str string) bool

IsSHA3512 checks is a string is a SHA3-512 hash. Alias for `IsHash(str, "sha3-512")`

func IsSHA384

func IsSHA384(str string) bool

IsSHA384 checks is a string is a SHA384 hash. Alias for `IsHash(str, "sha384")`

func IsSHA512

func IsSHA512(str string) bool

IsSHA512 checks is a string is a SHA512 hash. Alias for `IsHash(str, "sha512")`

func IsSSN

func IsSSN(str string) bool

IsSSN will validate the given string as a U.S. Social Security Number

func IsSemver

func IsSemver(str string) bool

IsSemver checks if string is valid semantic version

func IsSnakeCase added in v0.0.3

func IsSnakeCase(str string) bool

func IsTiger128

func IsTiger128(str string) bool

IsTiger128 checks is a string is a Tiger128 hash. Alias for `IsHash(str, "tiger128")`

func IsTiger160

func IsTiger160(str string) bool

IsTiger160 checks is a string is a Tiger160 hash. Alias for `IsHash(str, "tiger160")`

func IsTiger192

func IsTiger192(str string) bool

IsTiger192 checks is a string is a Tiger192 hash. Alias for `IsHash(str, "tiger192")`

func IsTime

func IsTime(str string, format string) bool

IsTime checks if string is valid according to given format

func IsType

func IsType(v any, params ...string) bool

IsType checks if interface is of some type

func IsURL

func IsURL(str string) bool

IsURL checks if the string is an URL.

func IsUTFDigit

func IsUTFDigit(str string) bool

IsUTFDigit checks if the string contains only unicode radix-10 decimal digits. Empty string is valid.

func IsUTFLetter

func IsUTFLetter(str string) bool

IsUTFLetter checks if the string contains only unicode letter characters. Similar to IsAlpha but for all languages. Empty string is valid.

func IsUTFLetterNumeric

func IsUTFLetterNumeric(str string) bool

IsUTFLetterNumeric checks if the string contains only unicode letters and numbers. Empty string is valid.

func IsUTFNumeric

func IsUTFNumeric(str string) bool

IsUTFNumeric checks if the string contains only unicode numbers of any kind. Numbers can be 0-9 but also Fractions ¾,Roman Ⅸ and Hangzhou 〩. Empty string is valid.

func IsUUID

func IsUUID(str string) bool

IsUUID checks if the string is a UUID (version 3, 4 or 5).

func IsUUIDv3

func IsUUIDv3(str string) bool

IsUUIDv3 checks if the string is a UUID version 3.

func IsUUIDv4

func IsUUIDv4(str string) bool

IsUUIDv4 checks if the string is a UUID version 4.

func IsUUIDv5

func IsUUIDv5(str string) bool

IsUUIDv5 checks if the string is a UUID version 5.

func IsUnixFilePath

func IsUnixFilePath(str string) bool

IsUnixFilePath checks both relative & absolute paths in Unix

func IsUnixTime

func IsUnixTime(str string) bool

IsUnixTime checks if string is valid unix timestamp value

func IsUpperCase

func IsUpperCase(str string) bool

IsUpperCase checks if the string is uppercase. Empty string is valid.

func IsWhole

func IsWhole(value float64) bool

IsWhole returns true if value is whole number

func IsWinFilePath

func IsWinFilePath(str string) bool

IsWinFilePath checks both relative & absolute paths in Windows

func Matches

func Matches(str, pattern string) bool

Matches checks if string matches the pattern (pattern is regular expression) In case of error return false

func Max

func Max(str string, params ...string) bool

Max checks whether the value is less than or equal to the maximum value. If the value is not a number, it will be converted to a number before comparison.

func MaxStringLength

func MaxStringLength(str string, params ...string) bool

MaxStringLength checks string's maximum length (including multi byte strings)

func Min

func Min(str string, params ...string) bool

Min checks whether the value is greater than or equal to the minimum value. If the value is not a number, it will be converted to a number before comparison.

func MinStringLength

func MinStringLength(str string, params ...string) bool

MinStringLength checks string's minimum length (including multi byte strings)

func Range

func Range(str string, params ...string) bool

Range checks string's length

func Register

func Register(name, format string, fn Func)

Register registers a new validator function with additional parameters

func RuneLength

func RuneLength(str string, params ...string) bool

RuneLength checks string's length Alias for StringLength

func Sign

func Sign(value float64) float64

Sign returns signum of number: 1 in case of value > 0, -1 in case of value < 0, 0 otherwise

func StringLength

func StringLength(str string, params ...string) bool

StringLength checks string's length (including multi byte strings)

func StringMatches

func StringMatches(s string, params ...string) bool

StringMatches checks if a string matches a given pattern.

func Struct

func Struct(s interface{}) (bool, error)

Validation function that replaces the original Struct function

Types

type Error

type Error struct {
	Name      string
	Validator string
	Path      []string
	// contains filtered or unexported fields
}

Error encapsulates a name, an error and whether there's a custom error message or not.

func (Error) Error

func (e Error) Error() string

Error returns the string representation of the error.

func (Error) Message

func (e Error) Message() string

Message returns the error message.

type Errors

type Errors []error

Errors is an array of multiple errors and conforms to the error interface.

func (Errors) Error

func (es Errors) Error() string

Error returns a string representation of the errors.

func (Errors) Errors

func (e Errors) Errors() []Error

Errors returns all contained errors, recursively.

type Func

type Func func(str string, params ...string) bool

Func is a wrapper for validator functions that accept additional parameters.

Jump to

Keyboard shortcuts

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