validation

package
v0.0.0-...-202847b Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// Unknown is unresolved OS type
	Unknown = iota
	// Win is Windows type
	Win
	// Unix is *nix OS types
	Unix
)

Used by IsFilePath func

View Source
const RF3339WithoutZone = "2006-01-02T15:04:05"

Variables

View Source
var ISO3166List = []ISO3166Entry{}/* 249 elements not displayed */

ISO3166List based on https://www.iso.org/obp/ui/#search/code/ Code Type "Officially Assigned Codes"

View Source
var ISO693List = []ISO693Entry{}/* 184 elements not displayed */

ISO693List based on http://data.okfn.org/data/core/language-codes/r/language-codes-3b2.json

View Source
var LocaleList = map[string]LocaleEntry{}/* 731 elements not displayed */

LocaleList contains all locales and their English names. This variable should be a private variable to prevent race conditions caused by inexperienced developers modifying a map. Only reading from a fixed sized map is race free. If you modify this map during runtime you should go straight to hell.

Functions

func Abs

func Abs(value float64) float64

Abs returns absolute value of number

func ByteLength

func ByteLength(str []byte, min, max int) bool

ByteLength check string's length

func HasLowerCase

func HasLowerCase(str string) bool

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

func HasUpperCase

func HasUpperCase(str string) bool

HasUpperCase check if the string contians as least 1 uppercase. Empty string is valid.

func InRangeFloat64

func InRangeFloat64(value, left, right float64) bool

InRangeFloat64 returns true if value lies between left and right border.

func InRangeInt64

func InRangeInt64(value, left, right int64) bool

InRangeInt64 returns true if value lies between left and right border.

func InRangeUint64

func InRangeUint64(value, left, right uint64) bool

InRangeUint64 returns true if value lies between left and right border.

func IsASCII

func IsASCII(str string) bool

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

func IsAlpha

func IsAlpha(str string) bool

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

func IsAlphanumeric

func IsAlphanumeric(str string) bool

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

func IsBase64

func IsBase64(str string) bool

IsBase64 check if a string is base64 encoded. Optimized version without regex.

func IsBool

func IsBool(str string) bool

IsBool check if the string is a bool. Empty string is valid.

func IsByteLength

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

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

func IsCIDR

func IsCIDR(str string) bool

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

func IsCreditCard

func IsCreditCard(str string) bool

IsCreditCard check 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 check 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).

Example

This small example illustrate how to work with IsDivisibleBy function.

println("1024 is divisible by 64: ", IsDivisibleBy("1024", "64"))
Output:

func IsEmailRegexp

func IsEmailRegexp(str string) bool

IsEmailRegexp runs a complex regex check if the string is an email.

func IsEmailSimple

func IsEmailSimple(str string) bool

IsEmailSimple checks if the str contains one @.

func IsExistingEmail

func IsExistingEmail(email string) bool

IsExistingEmail check if the string is an email of existing domain. Looks up the MX record.

func IsFilePath

func IsFilePath(str string) (bool, int)

IsFilePath check is a string is Win or Unix file path and returns it's type.

func IsFloat

func IsFloat(str string) bool

IsFloat check if the string is a float.

func IsFullWidth

func IsFullWidth(str string) bool

IsFullWidth check if the string contains any full-width chars. Empty string is valid.

func IsHalfWidth

func IsHalfWidth(str string) bool

IsHalfWidth check if the string contains any half-width chars. Empty string is valid.

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 check if the string is a hexadecimal number.

func IsHexcolor

func IsHexcolor(str string) bool

IsHexcolor check 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 IsIP

func IsIP(str string) bool

IsIP checks if a string is either IP version 4 or 6.

func IsIPv4

func IsIPv4(str string) bool

IsIPv4 check if the string is an IP version 4.

func IsIPv6

func IsIPv6(str string) bool

IsIPv6 check if the string is an IP version 6.

func IsISBN

func IsISBN(str string, version int) bool

IsISBN check if the string is an ISBN (version 10 or 13). If version value is not equal to 10 or 13, it will be check both variants.

func IsISBN10

func IsISBN10(str string) bool

IsISBN10 check if the string is an ISBN version 10.

func IsISBN13

func IsISBN13(str string) bool

IsISBN13 check if the string is an ISBN version 13.

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 check if string is valid ISO currency code. Code must be upper case.

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 check if string str is a member of the set of strings params

func IsInt

func IsInt(str string) bool

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

func IsLatitude

func IsLatitude(str string) bool

IsLatitude check if a string is valid latitude.

func IsLocale

func IsLocale(lcid string) bool

IsLocale checks case-insensitive if the provided string is a locale.

func IsLongitude

func IsLongitude(str string) bool

IsLongitude check if a string is valid longitude.

func IsLowerCase

func IsLowerCase(str string) bool

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

func IsMAC

func IsMAC(str string) bool

IsMAC check 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 IsMongoID

func IsMongoID(str string) bool

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

func IsMultibyte

func IsMultibyte(str string) bool

IsMultibyte check 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 IsNotEmpty

func IsNotEmpty(str string) bool

IsNotEmpty check if the string is not empty.

func IsNotEmptyTrimSpace

func IsNotEmptyTrimSpace(str string) bool

IsNotEmptyTrimSpace check if the white space trimmed string is not empty.

func IsNull

func IsNull(str string) bool

IsNull check if the string is null.

func IsNumeric

func IsNumeric(str string) bool

IsNumeric check 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 check if the string contains printable ASCII chars only. Empty string is valid.

func IsRFC3339

func IsRFC3339(str string) bool

IsRFC3339 check if string is valid timestamp value according to RFC3339

func IsRFC3339WithoutZone

func IsRFC3339WithoutZone(str string) bool

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

func IsRGBcolor

func IsRGBcolor(str string) bool

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

func IsRequestURI

func IsRequestURI(rawurl string) bool

IsRequestURI check 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 check if the string rawurl, assuming it was received in an HTTP request, is a valid URL confirm to RFC 3986

func IsRsaPublicKey

func IsRsaPublicKey(str string, keylen int) bool

IsRsaPublicKey check if a string is valid public key with provided length

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 check if string is valid semantic version

func IsTime

func IsTime(str string, format string) bool

IsTime check if string is valid according to given format

func IsURL

func IsURL(str string) bool

IsURL check if the string is an URL.

func IsUTFDigit

func IsUTFDigit(str string) bool

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

func IsUTFLetter

func IsUTFLetter(str string) bool

IsUTFLetter check 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 check if the string contains only unicode letters and numbers. Empty string is valid.

func IsUTFNumeric

func IsUTFNumeric(str string) bool

IsUTFNumeric check 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 check if the string is a UUID (version 3, 4 or 5). Does not use regex. Highly optimized.

func IsUUIDv3

func IsUUIDv3(str string) bool

IsUUIDv3 check if the string is a UUID version 3. Does not use regex. Highly optimized.

func IsUUIDv4

func IsUUIDv4(str string) bool

IsUUIDv4 check if the string is a UUID version 4. Does not use regex. Highly optimized.

func IsUUIDv5

func IsUUIDv5(str string) bool

IsUUIDv5 check if the string is a UUID version 5. Does not use regex. Highly optimized.

func IsUpperCase

func IsUpperCase(str string) bool

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

func IsVariableWidth

func IsVariableWidth(str string) bool

IsVariableWidth check if the string contains a mixture of full and half-width chars. Empty string is valid.

func IsWhole

func IsWhole(value float64) bool

IsWhole returns true if value is whole number

func Matches

func Matches(str, pattern string) bool

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

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, min, max int) bool

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

Types

type ISO3166Entry

type ISO3166Entry struct {
	EnglishShortName string
	FrenchShortName  string
	Alpha2Code       string
	Alpha3Code       string
	Numeric          string
}

ISO3166Entry stores country codes

type ISO693Entry

type ISO693Entry struct {
	Alpha3bCode string
	Alpha2Code  string
	English     string
}

ISO693Entry stores ISO language codes

type LocaleEntry

type LocaleEntry struct {
	Locale  string
	English string
}

LocaleEntry defines an ISO locale code like: de_DE or en_US or zh-Hans-SG [Chinese (Simplified, Singapore)].

type Validator

type Validator interface {
	// Validate runs the validation process which becomes valid once
	// the error is nil.
	Validate() error
}

Validator general interface that a type has implemented for validation.

Jump to

Keyboard shortcuts

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