Documentation ¶
Index ¶
- Constants
- Variables
- func Abs(value float64) float64
- func ByteLength(str []byte, min, max int) bool
- func HasLowerCase(str string) bool
- func HasUpperCase(str string) bool
- func InRangeFloat64(value, left, right float64) bool
- func InRangeInt64(value, left, right int64) bool
- func InRangeUint64(value, left, right uint64) bool
- func IsASCII(str string) bool
- func IsAlpha(str string) bool
- func IsAlphanumeric(str string) bool
- func IsBase64(str string) bool
- func IsBool(str string) bool
- func IsByteLength(str string, min, max int) bool
- func IsCIDR(str string) bool
- func IsCreditCard(str string) bool
- func IsDNSName(str string) bool
- func IsDataURI(str string) bool
- func IsDialString(str string) bool
- func IsDivisibleBy(str, num string) bool
- func IsEmailRegexp(str string) bool
- func IsEmailSimple(str string) bool
- func IsExistingEmail(email string) bool
- func IsFilePath(str string) (bool, int)
- func IsFloat(str string) bool
- func IsFullWidth(str string) bool
- func IsHalfWidth(str string) bool
- func IsHash(str string, algorithm string) bool
- func IsHexadecimal(str string) bool
- func IsHexcolor(str string) bool
- func IsHost(str string) bool
- func IsIP(str string) bool
- func IsIPv4(str string) bool
- func IsIPv6(str string) bool
- func IsISBN(str string, version int) bool
- func IsISBN10(str string) bool
- func IsISBN13(str string) bool
- func IsISO3166Alpha2(str string) bool
- func IsISO3166Alpha3(str string) bool
- func IsISO4217(str string) bool
- func IsISO693Alpha2(str string) bool
- func IsISO693Alpha3b(str string) bool
- func IsIn(str string, params ...string) bool
- func IsInt(str string) bool
- func IsLatitude(str string) bool
- func IsLocale(lcid string) bool
- func IsLongitude(str string) bool
- func IsLowerCase(str string) bool
- func IsMAC(str string) bool
- func IsMongoID(str string) bool
- func IsMultibyte(str string) bool
- func IsNatural(value float64) bool
- func IsNegative(value float64) bool
- func IsNonNegative(value float64) bool
- func IsNonPositive(value float64) bool
- func IsNotEmpty(str string) bool
- func IsNotEmptyTrimSpace(str string) bool
- func IsNull(str string) bool
- func IsNumeric(str string) bool
- func IsPort(str string) bool
- func IsPositive(value float64) bool
- func IsPrintableASCII(str string) bool
- func IsRFC3339(str string) bool
- func IsRFC3339WithoutZone(str string) bool
- func IsRGBcolor(str string) bool
- func IsRequestURI(rawurl string) bool
- func IsRequestURL(rawurl string) bool
- func IsRsaPublicKey(str string, keylen int) bool
- func IsSSN(str string) bool
- func IsSemver(str string) bool
- func IsTime(str string, format string) bool
- func IsURL(str string) bool
- func IsUTFDigit(str string) bool
- func IsUTFLetter(str string) bool
- func IsUTFLetterNumeric(str string) bool
- func IsUTFNumeric(str string) bool
- func IsUUID(str string) bool
- func IsUUIDv3(str string) bool
- func IsUUIDv4(str string) bool
- func IsUUIDv5(str string) bool
- func IsUpperCase(str string) bool
- func IsVariableWidth(str string) bool
- func IsWhole(value float64) bool
- func Matches(str, pattern string) bool
- func Sign(value float64) float64
- func StringLength(str string, min, max int) bool
- type ISO3166Entry
- type ISO693Entry
- type LocaleEntry
- type Validator
Examples ¶
Constants ¶
const ( // Unknown is unresolved OS type Unknown = iota // Win is Windows type Win // Unix is *nix OS types Unix )
Used by IsFilePath func
const RF3339WithoutZone = "2006-01-02T15:04:05"
Variables ¶
var ISO3166List = []ISO3166Entry{}/* 249 elements not displayed */
ISO3166List based on https://www.iso.org/obp/ui/#search/code/ Code Type "Officially Assigned Codes"
var ISO693List = []ISO693Entry{}/* 184 elements not displayed */
ISO693List based on http://data.okfn.org/data/core/language-codes/r/language-codes-3b2.json
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 HasLowerCase ¶
HasLowerCase check if the string contains at least 1 lowercase. Empty string is valid.
func HasUpperCase ¶
HasUpperCase check if the string contians as least 1 uppercase. Empty string is valid.
func InRangeFloat64 ¶
InRangeFloat64 returns true if value lies between left and right border.
func InRangeInt64 ¶
InRangeInt64 returns true if value lies between left and right border.
func InRangeUint64 ¶
InRangeUint64 returns true if value lies between left and right border.
func IsAlphanumeric ¶
IsAlphanumeric check if the string contains only letters and numbers. Empty string is valid.
func IsByteLength ¶
IsByteLength check if the string's length (in bytes) falls in a range.
func IsCreditCard ¶
IsCreditCard check if the string is a credit card.
func IsDialString ¶
IsDialString validates the given string for usage with the various Dial() functions
func IsDivisibleBy ¶
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 ¶
IsEmailRegexp runs a complex regex check if the string is an email.
func IsEmailSimple ¶
IsEmailSimple checks if the str contains one @.
func IsExistingEmail ¶
IsExistingEmail check if the string is an email of existing domain. Looks up the MX record.
func IsFilePath ¶
IsFilePath check is a string is Win or Unix file path and returns it's type.
func IsFullWidth ¶
IsFullWidth check if the string contains any full-width chars. Empty string is valid.
func IsHalfWidth ¶
IsHalfWidth check if the string contains any half-width chars. Empty string is valid.
func IsHash ¶
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 ¶
IsHexadecimal check if the string is a hexadecimal number.
func IsHexcolor ¶
IsHexcolor check if the string is a hexadecimal color.
func IsISBN ¶
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 IsISO3166Alpha2 ¶
IsISO3166Alpha2 checks if a string is valid two-letter country code
func IsISO3166Alpha3 ¶
IsISO3166Alpha3 checks if a string is valid three-letter country code
func IsISO693Alpha2 ¶
IsISO693Alpha2 checks if a string is valid two-letter language code
func IsISO693Alpha3b ¶
IsISO693Alpha3b checks if a string is valid three-letter language code.
func IsLongitude ¶
IsLongitude check if a string is valid longitude.
func IsLowerCase ¶
IsLowerCase check if the string is lowercase. Empty string is valid.
func IsMAC ¶
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 ¶
IsMongoID check if the string is a valid hex-encoded representation of a MongoDB ObjectId.
func IsMultibyte ¶
IsMultibyte check if the string contains one or more multibyte chars. Empty string is valid.
func IsNonNegative ¶
IsNonNegative returns true if value >= 0
func IsNonPositive ¶
IsNonPositive returns true if value <= 0
func IsNotEmptyTrimSpace ¶
IsNotEmptyTrimSpace check if the white space trimmed string is not empty.
func IsPrintableASCII ¶
IsPrintableASCII check if the string contains printable ASCII chars only. Empty string is valid.
func IsRFC3339WithoutZone ¶
IsRFC3339WithoutZone check if string is valid timestamp value according to RFC3339 which excludes the timezone.
func IsRGBcolor ¶
IsRGBcolor check if the string is a valid RGB color in form rgb(RRR, GGG, BBB).
func IsRequestURI ¶
IsRequestURI check if the string rawurl, assuming it was received in an HTTP request, is an absolute URI or an absolute path.
func IsRequestURL ¶
IsRequestURL check if the string rawurl, assuming it was received in an HTTP request, is a valid URL confirm to RFC 3986
func IsRsaPublicKey ¶
IsRsaPublicKey check if a string is valid public key with provided length
func IsUTFDigit ¶
IsUTFDigit check if the string contains only unicode radix-10 decimal digits. Empty string is valid.
func IsUTFLetter ¶
IsUTFLetter check if the string contains only unicode letter characters. Similar to IsAlpha but for all languages. Empty string is valid.
func IsUTFLetterNumeric ¶
IsUTFLetterNumeric check if the string contains only unicode letters and numbers. Empty string is valid.
func IsUTFNumeric ¶
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 ¶
IsUUID check if the string is a UUID (version 3, 4 or 5). Does not use regex. Highly optimized.
func IsUUIDv3 ¶
IsUUIDv3 check if the string is a UUID version 3. Does not use regex. Highly optimized.
func IsUUIDv4 ¶
IsUUIDv4 check if the string is a UUID version 4. Does not use regex. Highly optimized.
func IsUUIDv5 ¶
IsUUIDv5 check if the string is a UUID version 5. Does not use regex. Highly optimized.
func IsUpperCase ¶
IsUpperCase check if the string is uppercase. Empty string is valid.
func IsVariableWidth ¶
IsVariableWidth check if the string contains a mixture of full and half-width chars. Empty string is valid.
func Matches ¶
Matches check if string matches the pattern (pattern is regular expression) In case of error return false
func Sign ¶
Sign returns signum of number: 1 in case of value > 0, -1 in case of value < 0, 0 otherwise
func StringLength ¶
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 ¶
ISO693Entry stores ISO language codes
type LocaleEntry ¶
LocaleEntry defines an ISO locale code like: de_DE or en_US or zh-Hans-SG [Chinese (Simplified, Singapore)].