### Install validatorgo Source: https://pkg.go.dev/github.com/bube054/validatorgo Use the go get command to add the library to your project. ```bash go get -u github.com/bube054/validatorgo ``` -------------------------------- ### IsIntOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsInt validation rule. ```go type IsIntOpts struct { Min *int // minimum integer Max *int // maximum integer Gt *int // integer to exceeds Lt *int // integer to subceed } ``` -------------------------------- ### Configure Option Fields Source: https://pkg.go.dev/github.com/bube054/validatorgo Use helper functions to create pointers for option struct fields, allowing specific overrides while defaulting others to nil. ```go validatorgo.Bool(true) // *bool validatorgo.String("foo") // *string validatorgo.Int(42) // *int validatorgo.Uint(10) // *uint validatorgo.Float64(3.14) // *float64 ``` ```go ok, _ := validatorgo.IsFQDN("example.com", &validatorgo.IsFQDNOpts{ RequireTld: validatorgo.Bool(false), // override default (true) AllowTrailingDot: validatorgo.Bool(true), }) ``` -------------------------------- ### IsBase64Opts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsBase64 validation rule. ```go type IsBase64Opts struct { UrlSafe *bool // checks whether string is url safe. } ``` -------------------------------- ### Configure IsLength validation Source: https://pkg.go.dev/github.com/bube054/validatorgo Use IsLengthOpts to specify minimum and maximum character length constraints. ```go type IsLengthOpts struct { Min *uint // Minimum character length Max *uint // Maximum character length } ``` -------------------------------- ### Configure IsLatLong validation Source: https://pkg.go.dev/github.com/bube054/validatorgo Use IsLatLongOpts to enable DMS (degrees, minutes, and seconds) checking. ```go type IsLatLongOpts struct { CheckDMS *bool // checks DMS(degrees, minutes, and seconds) } ``` -------------------------------- ### IsISO8601Opts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsISO8601 validation rule. ```go type IsISO8601Opts struct { Strict *bool // must be a date that has actually happened, is happening or will happen. StrictSeparator *bool // must be delimited by T } ``` -------------------------------- ### Use Numeric Pointer Helpers Source: https://pkg.go.dev/github.com/bube054/validatorgo Helper functions to return pointers to float64 or int values. ```go func Float64(v float64) *float64 ``` ```go func Int(v int) *int ``` -------------------------------- ### Import validatorgo Source: https://pkg.go.dev/github.com/bube054/validatorgo Import the package into your Go source files, optionally using an alias. ```go import ( "fmt" "github.com/bube054/validatorgo" ) ``` ```go import ( "fmt" vgo "github.com/bube054/validatorgo" ) ``` -------------------------------- ### IsBeforeOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsBefore validation rule with a comparison date. ```go type IsBeforeOpts struct { ComparisonDate *string // date to be compared to. Valid layouts are from the time package e.g LLayout, ANSIC, UnixDate, RubyDate, RFC822, RFC822Z, RFC850, RFC1123, RFC1123Z, Kitchen, Stamp, StampMilli, StampMicro, StampNano, DateTime, DateOnly, TimeOnly, StandardDateLayout, SlashDateLayout, DateTimeLayout, ISO8601Layout, ISO8601ZuluLayout, ISO8601WithMillisecondsLayout. } ``` -------------------------------- ### IsFloatOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsFloat validation rule. ```go type IsFloatOpts struct { Min *float64 Max *float64 Gt *float64 Lt *float64 Locale *string } ``` -------------------------------- ### IsEmptyOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsEmpty validation rule. ```go type IsEmptyOpts struct { IgnoreWhitespace *bool } ``` -------------------------------- ### Configure IsStrongPassword validation Source: https://pkg.go.dev/github.com/bube054/validatorgo Use IsStrongPasswordOpts to define minimum requirements for password complexity. ```go type IsStrongPasswordOpts struct { MinLength *int // passwords minimum length MinLowercase *int // passwords minimum lowercase letters MinUppercase *int // passwords minimum uppercase letters MinNumbers *int // passwords minimum numbers MinSymbols *int // passwords minimum symbols ``` -------------------------------- ### IsDecimalOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsDecimal validation rule. ```go type IsDecimalOpts struct { DecimalDigits ForceDecimal *bool // decimal/radix point must be present Locale *string // locale used } ``` -------------------------------- ### IsIMEIOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsIMEI validation rule. ```go type IsIMEIOpts struct { AllowHyphens *bool } ``` -------------------------------- ### Configure IsRgbColor validation Source: https://pkg.go.dev/github.com/bube054/validatorgo Use IsRgbOpts to require percent values or allow spaces in RGB color strings. ```go type IsRgbOpts struct { IncludePercentValues *bool // must use percent values 90% not 0-255 AllowSpaces *bool // whether to include spaces } ``` -------------------------------- ### IsDateOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsDate validation rule. ```go type IsDateOpts struct { Format *string StrictMode *bool } ``` -------------------------------- ### Define Time Option Variables Source: https://pkg.go.dev/github.com/bube054/validatorgo Configuration variables for time-related validation options. ```go var ( IsTimeOptsHourFormat24 string = "hour24" IsTimeOptsHourFormat12 string = "hour12" IsTimeOptsModeDefault string = "default" IsTimeOptsModeWithSeconds string = "withSeconds" ) ``` -------------------------------- ### IsURL(str string, opts *IsURLOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the provided string is a valid URL, with extensive configuration options for protocols, hosts, and ports. ```APIDOC ## IsURL(str string, opts *IsURLOpts) ### Description Checks if the string is a URL. Highly configurable — see godoc for full options including `Protocols`, `RequireTld`, `RequireProtocol`, `RequireHost`, `RequirePort`, `HostWhitelist`/`HostBlacklist`, `AllowFragments`, `MaxAllowedLength`, etc. ``` -------------------------------- ### IsByteLengthOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsByteLength validation rule. ```go type IsByteLengthOpts struct { Min *uint // minimum byte length Max *uint // maximum byte length } ``` -------------------------------- ### IsCreditCardOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsCreditCard validation rule. ```go type IsCreditCardOpts struct { Provider *string // credit card issuer } ``` -------------------------------- ### Configure IsNumeric validation Source: https://pkg.go.dev/github.com/bube054/validatorgo Use IsNumericOpts to toggle symbol requirements and specify locale. ```go type IsNumericOpts struct { NoSymbols *bool Locale *string } ``` -------------------------------- ### IsFQDNOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsFQDN validation rule. ```go type IsFQDNOpts struct { RequireTld *bool AllowUnderscores *bool AllowTrailingDot *bool AllowNumericTld *bool IgnoreMaxLength *bool } ``` -------------------------------- ### Configure IsObject validation Source: https://pkg.go.dev/github.com/bube054/validatorgo Use IsObjectOpts to toggle strictness of object validation. ```go type IsObjectOpts struct { Strict *bool // looseness or strictness } ``` -------------------------------- ### Define IsTimeOpts Source: https://pkg.go.dev/github.com/bube054/validatorgo Configuration struct for the IsTime validator. ```go type IsTimeOpts struct { HourFormat *string // hour12 e.g 14:30 or hour24 e.g 02:30 PM Mode *string // default e.g 13:30 or withSeconds e.g 13:30:20 } ``` -------------------------------- ### IsEmpty(str string, opts *IsEmptyOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is zero-length. IsEmptyOpts defaults to { IgnoreWhitespace: false }. ```APIDOC ## IsEmpty(str string, opts *IsEmptyOpts) ### Description Checks if the string is zero-length. IsEmptyOpts defaults to { IgnoreWhitespace: false }. ``` -------------------------------- ### IsCurrencyOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsCurrency validation rule with extensive formatting options. ```go type IsCurrencyOpts struct { // deals with the options for currency Symbol *string // '$10.50' RequireSymbol *bool // $10.50 AllowSpaceAfterSymbol *bool // $ 10.50 SymbolAfterDigits *bool // 10.50$ // deals with the numeric signs AllowNegatives *bool // -$10.50 ParensForNegatives *bool // ($10.50) NegativeSignBeforeDigits *bool // $-10.50 NegativeSignAfterDigits *bool // $10.50- AllowNegativeSignPlaceholder *bool // $ 10.50 // deals with the decimals/separator ThousandSeparator *string // 10,000.50 DecimalSeparator *string // 10.50 AllowDecimal *bool // $10.00 RequireDecimal *bool // $10.00 MaxDigitsAfterDecimal *uint // $10.50 AllowSpaceAfterDigits *bool // '$ 10.50 } ``` -------------------------------- ### IsEmailOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsEmail validation rule. ```go type IsEmailOpts struct { AllowDisplayName *bool RequireDisplayName *bool AllowUTF8LocalPart *bool RequireTld *bool IgnoreMaxLength *bool AllowIpDomain *bool DomainSpecificValidation *bool BlacklistedChars *string HostBlacklist []string HostWhitelist []string } ``` -------------------------------- ### Validate an email with options Source: https://pkg.go.dev/github.com/bube054/validatorgo Validate email addresses using default settings or custom options. ```go // Pass nil to use all defaults ok, _ := vgo.IsEmail("user@example.com", nil) fmt.Println(ok) // true // Or customize only what you need ok, err := vgo.IsEmail("user@example.com", &vgo.IsEmailOpts{ RequireTld: vgo.Bool(false), // override default (true) DomainSpecificValidation: true, }) fmt.Println(ok, err) // true ``` -------------------------------- ### IsBooleanOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsBoolean validation rule. ```go type IsBooleanOpts struct { Loose *bool // strictness of the equality } ``` -------------------------------- ### Validate MIME Type Source: https://pkg.go.dev/github.com/bube054/validatorgo Verifies if the provided string conforms to a valid MIME type format. ```go ok, _ := validatorgo.IsMimeType("text/plain") fmt.Println(ok) // true ok, _ = validatorgo.IsMimeType("textplain") fmt.Println(ok) // false ``` -------------------------------- ### IsISSNOpts Configuration Source: https://pkg.go.dev/github.com/bube054/validatorgo Configures the IsISSN validation rule. ```go type IsISSNOpts struct { RequireHyphen *bool // requires a hyphen CaseSensitive *bool // must be exact case } ``` -------------------------------- ### Configure IsMobilePhone validation Source: https://pkg.go.dev/github.com/bube054/validatorgo Use IsMobilePhoneOpts to enforce strict format matching. ```go type IsMobilePhoneOpts struct { StrictMode *bool // matches format exactly } ``` -------------------------------- ### Matches(str string, re *regexp.Regexp) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string matches the given regex. ```APIDOC ## Matches(str string, re *regexp.Regexp) ### Description Checks if the string matches the given regex. ``` -------------------------------- ### Define Country and Locale Variables Source: https://pkg.go.dev/github.com/bube054/validatorgo Arrays containing various ISO standard codes and locale identifiers. ```go var AllCountryCodes = [...]string{} /* 237 elements not displayed */ ``` ```go var AllISO31661Alpha2 = [...]string{}/* 676 elements not displayed */ ``` ```go var AllISO31661Alpha3 = [...]string{}/* 243 elements not displayed */ ``` ```go var AllISO31661Numeric = [...]string{} /* 251 elements not displayed */ ``` ```go var AllISO4217Codes = [...]string{}/* 184 elements not displayed */ ``` ```go var AllISO6391Codes = [...]string{} /* 176 elements not displayed */ ``` ```go var AllLocales = [...]string{} /* 490 elements not displayed */ ``` -------------------------------- ### Define IsStrongPasswordOpts Source: https://pkg.go.dev/github.com/bube054/validatorgo Configuration struct for the IsStrongPassword validator. ```go type IsStrongPasswordOpts struct { PointsPerUnique *float64 // minimum points per unique character PointsPerRepeat *float64 // minimum points per repeated character PointsForContainingLower *float64 // minimum points per lowercase character PointsForContainingUpper *float64 // minimum points per uppercase character PointsForContainingNumber *float64 // minimum points per numeric character PointsForContainingSymbol *float64 // minimum points per special character } ``` -------------------------------- ### IsFloat(str string, opts *IsFloatOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a float. Supports Min/Max (≤ ≥), Gt/Lt (strict), and Locale. ```APIDOC ## IsFloat(str string, opts *IsFloatOpts) ### Description Checks if the string is a float. Supports Min/Max (≤ ≥), Gt/Lt (strict), and Locale. ``` -------------------------------- ### Configure IsMailtoURI validation Source: https://pkg.go.dev/github.com/bube054/validatorgo Use IsMailToURIOpts to configure email validation within a mailto URI. ```go type IsMailToURIOpts struct { IsEmailOpts } ``` -------------------------------- ### func Whitelist(str, whitelistedChars string) string Source: https://pkg.go.dev/github.com/bube054/validatorgo/sanitizer Removes characters from the string that do not appear in the provided whitelist. ```APIDOC ## func Whitelist(str, whitelistedChars string) string ### Description Removes characters that do not appear in the whitelist. The characters are used in a RegExp. ### Parameters - **str** (string) - The input string. - **whitelistedChars** (string) - The characters allowed to remain. ### Example ```go str := sanitizer.Whitelist("Hello123 World!", "a-zA-Z") ``` ``` -------------------------------- ### IsInt(str string, opts *IsIntOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is an integer. Supports Min, Max, Gt, Lt, and AllowLeadingZeroes. ```APIDOC ## IsInt(str string, opts *IsIntOpts) ### Description Checks if the string is an integer. Supports Min, Max, Gt, Lt, and AllowLeadingZeroes. ``` -------------------------------- ### Define Date Layout Constants Source: https://pkg.go.dev/github.com/bube054/validatorgo/sanitizer Standardized date and time layout constants used for parsing or formatting date strings. ```go const ( StandardDateLayout = "2006-01-02" SlashDateLayout = "2006/01/02" DateTimeLayout = "2006-01-02 15:04:05" ISO8601Layout = "2006-01-02T15:04:05" ISO8601ZuluLayout = "2006-01-02T15:04:05Z" ISO8601WithMillisecondsLayout = "2006-01-02T15:04:05.000Z" ) ``` -------------------------------- ### Use Bool Pointer Helper Source: https://pkg.go.dev/github.com/bube054/validatorgo Returns a pointer to a boolean value, useful for option structs. ```go func Bool(v bool) *bool ``` ```go IsEmail("x@y.com", &IsEmailOpts{AllowUTF8LocalPart: Bool(false)}) ``` -------------------------------- ### IsSemVer Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is a valid Semantic Version. ```APIDOC ## func IsSemVer(str string) (bool, error) ### Description Validates that the string follows the Semantic Versioning Specification. ### Parameters - **str** (string) - The version string. ``` -------------------------------- ### Validate SemVer Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid Semantic Versioning (SemVer) string. ```go ok, _ := validatorgo.IsSemVer("1.0.0") fmt.Println(ok) // true ok, _ = validatorgo.IsSemVer("1.0.0.0") fmt.Println(ok) // false ``` -------------------------------- ### Validate Currency Format Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is a valid currency amount using IsCurrencyOpts for configuration. ```go ok, _ := validatorgo.IsCurrency("$100,000.00", nil) fmt.Println(ok) // true ok, _ = validatorgo.IsCurrency("¥100", &validatorgo.IsCurrencyOpts{Symbol: String("¥"), RequireSymbol: Bool(true)}) fmt.Println(ok) // true ok, _ = validatorgo.IsCurrency("100.50", &validatorgo.IsCurrencyOpts{Symbol: String("$"), RequireSymbol: Bool(true)}) fmt.Println(ok) // false ``` -------------------------------- ### Validate URL Source: https://pkg.go.dev/github.com/bube054/validatorgo Validates a URL string with configurable options like protocol requirements, host validation, and length constraints. ```go ok, _ := validatorgo.IsURL("http://localhost", &validatorgo.IsURLOpts{RequireTld: Bool(false), AllowProtocolRelativeUrls: Bool(true)}) fmt.Println(ok) // true ok, _ = validatorgo.IsURL("example.com", &validatorgo.IsURLOpts{RequireProtocol: Bool(true), AllowProtocolRelativeUrls: Bool(true)}) fmt.Println(ok) // false ``` -------------------------------- ### Validate Whitelist Membership Source: https://pkg.go.dev/github.com/bube054/validatorgo Verifies that all characters in the input string are present in the provided whitelist string. ```go ok, _ := validatorgo.IsWhitelisted("stop", "post") fmt.Println(ok) // true ok, _ = validatorgo.IsWhitelisted("bang", "take") fmt.Println(ok) // false ``` -------------------------------- ### Configure IsMacAddress validation Source: https://pkg.go.dev/github.com/bube054/validatorgo Use IsMacAddressOpts to restrict separators or specify the MAC address type. ```go type IsMacAddressOpts struct { NoSeparators *bool // will not allow separators Type *string // mac address type } ``` -------------------------------- ### IsBefore(str string, opts *IsBeforeOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a date before the given ComparisonDate (defaults to now). ```APIDOC ## IsBefore(str string, opts *IsBeforeOpts) ### Description Checks if the string is a date before the given ComparisonDate (defaults to now). ``` -------------------------------- ### IsEmail(str string, opts *IsEmailOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the provided string is a valid email address, with optional configuration for display names, TLD requirements, and blacklists. ```APIDOC ## IsEmail(str string, opts *IsEmailOpts) ### Description Checks if the string is an email. Supports `AllowDisplayName`, `RequireDisplayName`, `AllowUTF8LocalPart`, `RequireTld`, `AllowIpDomain`, `DomainSpecificValidation`, `BlacklistedChars`, `HostBlacklist`, `HostWhitelist`, `IgnoreMaxLength`. ``` -------------------------------- ### IsDate(str string, opts *IsDateOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid date (e.g. 2002-07-15). Supports Format and StrictMode. ```APIDOC ## IsDate(str string, opts *IsDateOpts) ### Description Checks if the string is a valid date (e.g. 2002-07-15). Supports Format and StrictMode. ``` -------------------------------- ### Convert String to Date Source: https://pkg.go.dev/github.com/bube054/validatorgo/sanitizer Parses a string into a pointer to time.Time. Returns nil if the input does not match supported time layouts. ```go date := sanitizer.ToDate("Mon Jan 2 15:04:05 2006") dateAsStr := date.String() fmt.Println(dateAsStr) // "2006-01-02 15:04:05 +0000 UTC" ``` -------------------------------- ### Validate Data URI Source: https://pkg.go.dev/github.com/bube054/validatorgo Validates if a string follows the data URI format. ```go ok, _ := validatorgo.IsDataURI("data:,Hello%2C%20World%21") fmt.Println(ok) // true ok, _ = validatorgo.IsDataURI("text/plain;base64,SGVsbG8sIFdvcmxkIQ==") fmt.Println(ok) // false ``` -------------------------------- ### Validate Fully Qualified Domain Name Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is a fully qualified domain name. Configuration options include TLD requirements and wildcard support. ```go ok, _ := validatorgo.IsFQDN("localhost", nil) fmt.Println(ok) // true ok, _ = validatorgo.IsFQDN("example..com", nil) fmt.Println(ok) // false ``` -------------------------------- ### Sanitize a string Source: https://pkg.go.dev/github.com/bube054/validatorgo Clean strings using the sanitizer package. ```go import "github.com/bube054/validatorgo/sanitizer" clean := sanitizer.Whitelist("Hello123 World!", "a-zA-Z") fmt.Println(clean) // "HelloWorld" ``` -------------------------------- ### IsByteLength(str string, opts *IsByteLengthOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string's UTF-8 byte length falls within a range. Defaults to { Min: 0, Max: nil }. ```APIDOC ## IsByteLength(str string, opts *IsByteLengthOpts) ### Description Checks if the string's UTF-8 byte length falls within a range. Defaults to { Min: 0, Max: nil }. ``` -------------------------------- ### Validate Magnet URI Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string follows the Magnet URI format. ```go ok, _ := validatorgo.IsMagnetURI("magnet:?xt=urn:btih:123456789abcdef123456789abcdef123456789a") fmt.Println(ok) // true ok, _ = validatorgo.IsMagnetURI("magnet:?dn=Example&tr=http://example.com/announce") fmt.Println(ok) // false ``` -------------------------------- ### IsAfter(str string, opts *IsAfterOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a date after the given ComparisonDate (defaults to now). ```APIDOC ## IsAfter(str string, opts *IsAfterOpts) ### Description Checks if the string is a date after the given ComparisonDate (defaults to now). ``` -------------------------------- ### Convert String to Float Source: https://pkg.go.dev/github.com/bube054/validatorgo/sanitizer Converts a string to a float64, returning an error if the input is not a valid float. ```go flt := sanitizer.ToFloat("123.45") fmt.Println(flt) // 123.45 ``` -------------------------------- ### IsTime(str string, opts *IsTimeOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid time (e.g. 23:01:59). Supports HourFormat (hour12/hour24) and Mode (default/withSeconds). ```APIDOC ## IsTime(str string, opts *IsTimeOpts) ### Description Checks if the string is a valid time (e.g. 23:01:59). Supports HourFormat (hour12/hour24) and Mode (default/withSeconds). ``` -------------------------------- ### IsFQDN Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a fully qualified domain name. ```APIDOC ## func IsFQDN(str string, opts *IsFQDNOpts) (bool, error) ### Description A validator that checks if the string is a fully qualified domain name (e.g. domain.com). ### Parameters - **str** (string) - The string to validate. - **opts** (*IsFQDNOpts) - Optional configuration for FQDN validation. ``` -------------------------------- ### Validate Date Format Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is a valid date, optionally using strict mode and custom layouts. ```go ok, _ := validatorgo.IsDate("2006-01-02", nil) fmt.Println(ok) // true ok, _ = validatorgo.IsDate("01/023/2006", nil) fmt.Println(ok) // false ``` -------------------------------- ### Validate Integer Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is an integer. The IsIntOpts struct allows for boundary checks and leading zero configuration. ```go ok, _ := validatorgo.IsInt("123", nil) fmt.Println(ok) // true ok, _ = validatorgo.IsInt("123.45", nil) fmt.Println(ok) // false ``` -------------------------------- ### func IsCurrency(str string, opts *IsCurrencyOpts) (bool, error) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the provided string is a valid currency amount based on the provided options. ```APIDOC ## func IsCurrency(str string, opts *IsCurrencyOpts) (bool, error) ### Description A validator that checks if the string is a valid currency amount. ### Parameters - **str** (string) - The string to validate. - **opts** (*IsCurrencyOpts) - Optional configuration struct for currency validation rules. ``` -------------------------------- ### Validate Date Comparison with IsAfter Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string date is after a specified comparison date using IsAfterOpts. ```go ok, _ := validatorgo.IsAfter("2023-09-15", &validatorgo.IsAfterOpts{ComparisonDate: "2023-01-01"}) fmt.Println(ok) // true ok, _ = validatorgo.IsAfter("2023-01-01", &validatorgo.IsAfterOpts{ComparisonDate: "2023-09-15"}) fmt.Println(ok) // false ``` -------------------------------- ### func ToDate Source: https://pkg.go.dev/github.com/bube054/validatorgo/sanitizer Converts a string to a time.Time pointer. ```APIDOC ## func ToDate(str string) *time.Time ### Description Converts the input string to a pointer to time.Time. Returns nil if the input does not match a supported time layout. ### Parameters - **str** (string) - The date string to convert. ``` -------------------------------- ### Validate String Equality Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string matches a comparison string exactly. ```go func Equals(str, comparison string) (bool, error) ``` ```go ok, _ := validatorgo.Equals("Hello", "Hello") fmt.Println(ok) // true ok, _ = validatorgo.Equals("Hello", "World") fmt.Println(ok) // false ``` -------------------------------- ### Validate Locale Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the provided string is a valid locale. ```go ok, _ := validatorgo.IsLocale("ca_ES") fmt.Println(ok) // true ok, _ = validatorgo.IsLocale("en_XY") fmt.Println(ok) // false ``` -------------------------------- ### Validate Array Format with IsArray Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string represents a valid array, with optional length constraints. ```go ok, _ := validatorgo.IsArray(`["item1", "item2"]`, nil) fmt.Println(ok) // true ok, _ = validatorgo.IsArray(`{"name": "John", "age": 30}`, nil) fmt.Println(ok) // false ``` -------------------------------- ### IsIP(str, version string) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is an IP address, supporting IPv4, IPv6, or both. ```APIDOC ## IsIP(str, version string) ### Description Checks if the string is an IP address. `version` is "4", "6", or empty for both. ``` -------------------------------- ### Define IsURLOpts Source: https://pkg.go.dev/github.com/bube054/validatorgo Configuration struct for the IsURL validator. ```go type IsURLOpts struct { Protocols []string RequireTld *bool RequireProtocol *bool RequireHost *bool RequirePort *bool RequireValidProtocol *bool AllowUnderscores *bool HostWhitelist []string HostBlacklist []string AllowTrailingDot *bool AllowProtocolRelativeUrls *bool AllowFragments *bool AllowQueryComponents *bool DisallowAuth *bool ValidateLength *bool MaxAllowedLength *int } ``` -------------------------------- ### Equals(str, comparison string) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string matches the comparison. ```APIDOC ## Equals(str, comparison string) ### Description Checks if the string matches the comparison. ``` -------------------------------- ### IsISO8601(str string, opts *IsISO8601Opts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid ISO 8601 date. Supports Strict and StrictSeparator. ```APIDOC ## IsISO8601(str string, opts *IsISO8601Opts) ### Description Checks if the string is a valid ISO 8601 date. Supports Strict and StrictSeparator. ``` -------------------------------- ### Validate MD5 Hash Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid MD5 hash. ```go ok, _ := validatorgo.IsMD5("9e107d9d372bb6826bd81d3542a419d6") fmt.Println(ok) // true ok, _ = validatorgo.IsMD5("9e107d9d372bb6826bd81d3542a419d") fmt.Println(ok) // false ``` -------------------------------- ### IsMimeType Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string matches a valid MIME type format. ```APIDOC ## func IsMimeType(str string) (bool, error) ### Description A validator that checks if the string matches to a valid MIME type format. ### Parameters - **str** (string) - Required - The string to validate. ``` -------------------------------- ### func ToFloat Source: https://pkg.go.dev/github.com/bube054/validatorgo/sanitizer Converts a string to a float64. ```APIDOC ## func ToFloat(str string) (float64, error) ### Description Converts the input string to a float64. Returns an error if the input is not a valid float. ### Parameters - **str** (string) - The string to convert. ``` -------------------------------- ### IsEmpty Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string has a length of zero. ```APIDOC ## func IsEmpty(str string, opts *IsEmptyOpts) (bool, error) ### Description A validator check if the string has a length of zero. ### Parameters - **str** (string) - The string to check. - **opts** (*IsEmptyOpts) - Optional configuration, defaults to { IgnoreWhitespace: false }. ``` -------------------------------- ### Define Object Strictness Variable Source: https://pkg.go.dev/github.com/bube054/validatorgo Default configuration for object validation strictness. ```go var ( IsObjectOptsDefaultStrict = true ) ``` -------------------------------- ### IsISO6391 Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the provided string is a valid ISO 639-1 language code. ```APIDOC ## func IsISO6391(str string) (bool, error) ### Description A validator that checks if the string is a valid ISO 639-1 language code. ### Parameters - **str** (string) - Required - The string to validate. ``` -------------------------------- ### IsDecimal(str string, opts *IsDecimalOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string represents a decimal number (0.1, .3, 1.1, etc.). Supports ForceDecimal, DecimalDigits, and Locale. ```APIDOC ## IsDecimal(str string, opts *IsDecimalOpts) ### Description Checks if the string represents a decimal number (0.1, .3, 1.1, etc.). Supports ForceDecimal, DecimalDigits, and Locale. ``` -------------------------------- ### Validate BTC Address with IsBTCAddress Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is a valid Bitcoin address. ```go ok, _ := validatorgo.IsBTCAddress("1RAHUEYstWetqabcFn5Au4m4GFg7xJaNVN2") fmt.Println(ok) // true ok, _ = validatorgo.IsBTCAddress("0J98t1RHT73CNmQwertyyWrnqRhWNLy") fmt.Println(ok) // false ``` -------------------------------- ### Validate IP Address Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid IPv4 or IPv6 address. ```go ok, _ := validatorgo.IsIP("192.168.0.1", "4") fmt.Println(ok) // true ok, _ = validatorgo.IsIP("256.256.256.256", "4") fmt.Println(ok) // false ``` -------------------------------- ### Validate Slug Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid slug format. ```go ok, _ := validatorgo.IsSlug("rgb(255,0,0)") fmt.Println(ok) // true ok, _ = validatorgo.IsSlug("rgb( 255 , 0 , 0 )") fmt.Println(ok) // false ``` -------------------------------- ### Validate Base32 Encoding with IsBase32 Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is base32 encoded, with an option to use Crockford's base32 alternative. ```go ok, _ := validatorgo.IsBase32("JBSWY3DPEBLW64TMMQ", nil) fmt.Println(ok) // true ok, _ = validatorgo.IsBase32("jbswy3dpeblw64tmmq======", nil) fmt.Println(ok) // false ``` -------------------------------- ### Validate ISBN Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid ISBN-10 or ISBN-13. ```go ok, _ := validatorgo.IsISBN("0-7167-0344-0", "10") fmt.Println(ok) // true ok, _ = validatorgo.IsISBN("0-7168-0344-0", "10") fmt.Println(ok) // false ``` -------------------------------- ### Validate Regex Match Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string matches a provided regular expression pattern. ```go ok, _ := validatorgo.Matches("foo", regexp.MustCompile(`^foo$`)) fmt.Println(ok) // true ok, _ = validatorgo.Matches("foo", regexp.MustCompile(`^foobar$`)) fmt.Println(ok) // false ``` -------------------------------- ### IsISBN Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid ISBN. ```APIDOC ## func IsISBN(str, version string) (bool, error) ### Description A validator that checks if the string is an ISBN. ### Parameters - **str** (string) - Required - The ISBN string. - **version** (string) - Optional - The ISBN version ("10" or "13"). ``` -------------------------------- ### Validate Password Strength Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string meets password strength criteria. The second argument accepts an IsStrongPasswordOpts struct for custom configuration. ```go ok, _, _ := validatorgo.IsStrongPassword("Password123!", nil) fmt.Println(ok) // true ok, _, _ = validatorgo.IsStrongPassword("P@ss1", nil) fmt.Println(ok) // false ``` -------------------------------- ### Validate Ethereum Address Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is a valid Ethereum address format. Note that this does not validate address checksums. ```go ok, _ := validatorgo.IsEthereumAddress("0xeA0B9657892321121287128712BC78A89F989AAA") fmt.Println(ok) // true ok, _ = validatorgo.IsEthereumAddress("0xiuahbsndakjsd") fmt.Println(ok) // false ``` -------------------------------- ### IsHalfWidth(str string) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string contains any half-width characters. ```APIDOC ## IsHalfWidth(str string) ### Description Checks if the string contains any half-width characters. ``` -------------------------------- ### IsISO8601 Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the provided string is a valid ISO 8601 date. ```APIDOC ## func IsISO8601(str string, opts *IsISO8601Opts) (bool, error) ### Description A validator that checks if the string is a valid ISO 8601 date. IsISO8601Opts defaults to { Strict: false, StrictSeparator: false }. ``` -------------------------------- ### Validate Date Comparison Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string represents a date before a specified comparison date. Supports various time layouts. ```go ok, _ := validatorgo.IsBefore("2023-01-01", &validatorgo.IsBeforeOpts{ComparisonDate: "2023-09-15"}) fmt.Println(ok) // true ok, _ = validatorgo.IsBefore("2024-01-01", &validatorgo.IsBeforeOpts{ComparisonDate: "2023-01-01"}) fmt.Println(ok) // false ``` -------------------------------- ### IsFullWidth(str string) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string contains any full-width characters. ```APIDOC ## IsFullWidth(str string) ### Description Checks if the string contains any full-width characters. ``` -------------------------------- ### Define Error Code Constants Source: https://pkg.go.dev/github.com/bube054/validatorgo Constants representing various validation failure scenarios. ```go const ( ErrInvalidFormat = "invalid_format" ErrTooShort = "too_short" ErrTooLong = "too_long" ErrMissingTLD = "missing_tld" ErrBlacklistedHost = "blacklisted_host" ErrNotWhitelistedHost = "not_whitelisted_host" ErrBlacklistedChar = "blacklisted_char" ErrInvalidLocale = "invalid_locale" ErrOutOfRange = "out_of_range" ErrInvalidChecksum = "invalid_checksum" ErrInvalidLength = "invalid_length" ErrMissingRequired = "missing_required" ErrInvalidDomain = "invalid_domain" ErrUnsupportedVersion = "unsupported_version" ErrInvalidValue = "invalid_value" ErrNotFound = "not_found" ) ``` -------------------------------- ### Validate Empty String Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string has a length of zero. The optional IsEmptyOpts struct supports ignoring whitespace. ```go ok, _ := validatorgo.IsEmpty("", nil) fmt.Println(ok) // true ok, _ = validatorgo.IsEmpty("abc", nil) fmt.Println(ok) // false ``` -------------------------------- ### Validate RFC 3339 Date Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string conforms to the RFC 3339 date format. ```go ok, _ := validatorgo.IsRFC3339("2024-09-21T14:30:00Z") fmt.Println(ok) // true ok, _ = validatorgo.IsRFC3339("2024-09-21 14:30:00Z") fmt.Println(ok) // false ``` -------------------------------- ### func IsBTCAddress Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid Bitcoin address. ```APIDOC ## func IsBTCAddress(str string) (bool, error) ### Description Validates if the input string conforms to the Bitcoin address format. ### Parameters - **str** (string) - The string to validate. ``` -------------------------------- ### Validate RGB Color Source: https://pkg.go.dev/github.com/bube054/validatorgo Validates RGB or RGBA color strings. Use IsRgbOpts to configure percentage support and whitespace allowance. ```go ok, _ := validatorgo.IsRgbColor("rgb(255,0,0)", nil) fmt.Println(ok) // true ok, _ = validatorgo.IsRgbColor("rgb( 255 , 0 , 0 )", nil) fmt.Println(ok) // false ``` -------------------------------- ### Validate ISO 639-1 Language Code Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is a valid ISO 639-1 language code. ```go ok, _ := validatorgo.IsISO6391("en") fmt.Println(ok) // true ok, _ = validatorgo.IsISO6391("eng") fmt.Println(ok) // false ``` -------------------------------- ### IsLicensePlate Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string matches the format of a country's license plate. ```APIDOC ## func IsLicensePlate(str string, locale string) (bool, error) ### Description A validator that checks if the string matches the format of a country's license plate. ### Parameters - **str** (string) - The license plate string. - **locale** (string) - The locale code (e.g., "cs-CZ", "de-DE", "en-IN", "any"). ### Returns - **bool** - True if valid, false otherwise. ``` -------------------------------- ### Trim characters with Trim Source: https://pkg.go.dev/github.com/bube054/validatorgo/sanitizer Removes specified characters from both sides of the input string. Defaults to whitespace if no characters are provided. ```go str := sanitizer.Trim(" Hello World ", "") fmt.Println(str) // "Hello World" ``` -------------------------------- ### Contains(str, seed string, opts *ContainsOpt) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string contains a seed. ContainsOpt defaults to { IgnoreCase: false, MinOccurrences: 1 }. ```APIDOC ## Contains(str, seed string, opts *ContainsOpt) ### Description Checks if a string contains a seed. ContainsOpt defaults to { IgnoreCase: false, MinOccurrences: 1 }. ``` -------------------------------- ### Validate Time Format Source: https://pkg.go.dev/github.com/bube054/validatorgo Validates time strings based on 12 or 24-hour formats and optional seconds. Use IsTimeOpts to configure HourFormat and Mode. ```go ok, _ := validatorgo.IsTime("14:30", nil) fmt.Println(ok) // true ok, _ = validatorgo.IsTime("09:5", nil) fmt.Println(ok) // false ``` -------------------------------- ### IsBoolean(str string, opts *IsBooleanOpts) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a boolean. ```APIDOC ## IsBoolean(str string, opts *IsBooleanOpts) ### Description Checks if the string is a boolean. ``` -------------------------------- ### Validate MAC Address Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid MAC address, with optional support for no separators or different address types. ```go ok, _ := validatorgo.IsMacAddress("00:1A:2B:3C:4D:5E", nil) fmt.Println(ok) // true ok, _ = validatorgo.IsMacAddress("00:1A:2B:3C:4D:ZZ", nil) fmt.Println(ok) // false ``` -------------------------------- ### Validate IP Range Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid IP range for IPv4 or IPv6. ```go ok, _ := validatorgo.IsIPRange("192.168.0.0/24", "4") fmt.Println(ok) // true ok, _ = validatorgo.IsIPRange("192.168.0.0/33", "4") fmt.Println(ok) // false ``` -------------------------------- ### Validate Port Number Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the input string is a valid port number. ```go ok, _ := validatorgo.IsPort("07") fmt.Println(ok) // true ok, _ = validatorgo.IsPort("078") fmt.Println(ok) // false ``` -------------------------------- ### func IsDataURI(str string) (bool, error) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the provided string is in a valid data URI format. ```APIDOC ## func IsDataURI(str string) (bool, error) ### Description A validator that checks if the string is a data uri format. ### Parameters - **str** (string) - The string to validate. ``` -------------------------------- ### Unescape HTML entities with Unescape Source: https://pkg.go.dev/github.com/bube054/validatorgo/sanitizer Replaces HTML encoded entities with their corresponding characters like <, >, &, ', ", `, \, and /. ```go str := sanitizer.Unescape("&") fmt.Println(str) // "&" ``` -------------------------------- ### IsVariableWidth(str string) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string contains a mixture of full and half-width characters. ```APIDOC ## IsVariableWidth(str string) ### Description Checks if the string contains a mixture of full and half-width characters. ``` -------------------------------- ### Validate String Length Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string's length falls within a specified range, accounting for surrogate pairs. ```go ok, _ := validatorgo.IsLength("hello", &validatorgo.IsLengthOpts{Min: 3}) fmt.Println(ok) // true ok, _ = validatorgo.IsLength("hi", &validatorgo.IsLengthOpts{Min: 3}) fmt.Println(ok) // false ``` -------------------------------- ### Convert string to integer with ToInt Source: https://pkg.go.dev/github.com/bube054/validatorgo/sanitizer Converts a string to an integer, returning an error if the input is not a valid integer. Note that this function may interpret inputs as octals. ```go num := sanitizer.ToInt("123") fmt.Println(num) // 123 ``` -------------------------------- ### Validate Lowercase Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string consists only of lowercase characters. ```go ok, _ := validatorgo.IsLowerCase("hello") fmt.Println(ok) // true ok, _ = validatorgo.IsLowerCase("WORLD") fmt.Println(ok) // false ``` -------------------------------- ### IsMailtoURI Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the provided string is in a valid Mailto URI format. ```APIDOC ## func IsMailtoURI(str string, opts *IsMailToURIOpts) (bool, error) ### Description A validator that checks if the string is a Mailto URI format. IsMailToURIOpts validates emails inside the URI. ### Parameters - **str** (string) - Required - The string to validate. - **opts** (*IsMailToURIOpts) - Optional - Configuration options for email validation within the URI. ``` -------------------------------- ### func IsStrongPassword Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string meets strong password criteria based on provided options. ```APIDOC ## func IsStrongPassword(str string, opts *IsStrongPasswordOpts) (bool, float64, error) ### Description A validator that checks if the string can be considered a strong password or not. Returns the validity and the score. ### Parameters - **str** (string) - The password string to validate. - **opts** (*IsStrongPasswordOpts) - Optional configuration for password strength requirements. ``` -------------------------------- ### Validate ULID Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the provided string is a valid ULID. ```go ok, _ := validatorgo.IsULID("01ARZ3NDEKTSV4RRFFQ69G5FAV") fmt.Println(ok) // true ok, _ = validatorgo.IsULID("01ARZ3NDEKTSV4RRFFQ69G5FA") fmt.Println(ok) // false ``` -------------------------------- ### IsEthereumAddress Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string is a valid Ethereum address. ```APIDOC ## func IsEthereumAddress(str string) (bool, error) ### Description A validator checks if the string is an Ethereum address. Does not validate address checksums. ### Parameters - **str** (string) - The string to validate. ``` -------------------------------- ### Validate Uppercase String Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string consists entirely of uppercase characters. ```go ok, _ := validatorgo.IsUpperCase("HELLO") fmt.Println(ok) // true ok, _ = validatorgo.IsUpperCase("world") fmt.Println(ok) // false ``` -------------------------------- ### Validate JSON Object Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is a valid JSON object. Use IsObjectOpts to toggle strict mode, where arrays and null values can be treated as objects. ```go ok, _ := validatorgo.IsObject(`{"name": "John", "age": 30}`, &validatorgo.IsObjectOpts{Strict: true}) fmt.Println(ok) // true ok, _ = validatorgo.IsObject(`{"name": "John", "age`, &validatorgo.IsObjectOpts{Strict: true}) fmt.Println(ok) // false ``` -------------------------------- ### func IsBase64 Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the provided string is base64 encoded, with optional URL-safe configuration. ```APIDOC ## func IsBase64(str string, opts *IsBase64Opts) (bool, error) ### Description A validator that checks if the string is base64 encoded. IsBase64Opts defaults to { UrlSafe: false }. When UrlSafe is true, it tests if the string is URL safe. ### Parameters - **str** (string) - The string to validate. - **opts** (*IsBase64Opts) - Optional configuration struct. ``` -------------------------------- ### IsObject Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is a valid JSON object. ```APIDOC ## func IsObject(str string, opts *IsObjectOpts) (bool, error) ### Description Validates that a string is a JSON object. By default, it uses strict mode. If Strict is false, arrays and null are also considered objects. ### Parameters - **str** (string) - The string to validate. - **opts** (*IsObjectOpts) - Configuration options (Strict: bool). ``` -------------------------------- ### Right Trim String Source: https://pkg.go.dev/github.com/bube054/validatorgo/sanitizer Removes specified characters from the right side of a string, defaulting to whitespace. ```go str := sanitizer.RTrim(" Hello World ", "") fmt.Println(str) // " Hello World" ``` -------------------------------- ### func IsVariableWidth(str string) (bool, error) Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if the string contains a mixture of full and half-width characters. ```APIDOC ## func IsVariableWidth(str string) (bool, error) ### Description A validator that checks if the string contains a mixture of full and half-width chars. ### Parameters - **str** (string) - Required - The string to check. ### Response - **bool** - Returns true if the string contains mixed width characters, false otherwise. - **error** - Returns an error if validation fails. ``` -------------------------------- ### Validate ISO 4217 Currency Code Source: https://pkg.go.dev/github.com/bube054/validatorgo Checks if a string is a valid ISO 4217 officially assigned currency code. ```go ok, _ := validatorgo.IsIso4217("AED") fmt.Println(ok) // true ok, _ = validatorgo.IsIso4217("AE") fmt.Println(ok) // false ``` -------------------------------- ### Implement Error interface for ValidationError Source: https://pkg.go.dev/github.com/bube054/validatorgo Method to satisfy the error interface for ValidationError. ```go func (e *ValidationError) Error() string ```