Documentation ¶
Index ¶
Constants ¶
const ( // Alpha represents regular expression for alpha characters Alpha string = "^[a-zA-Z]+$" // AlphaDash represents regular expression for alpha characters with underscore and dash AlphaDash string = "^[a-zA-Z0-9_-]+$" // AlphaSpace represents regular expression for alpha characters with underscore, space and dash AlphaSpace string = "^[-a-zA-Z0-9_ ]+$" // AlphaNumeric represents regular expression for alpha numeric characters AlphaNumeric string = "^[a-zA-Z0-9]+$" // CreditCard represents regular expression for credit cards like (Visa, MasterCard, American Express, Diners Club, Discover, and JCB cards). Ref: https://stackoverflow.com/questions/9315647/regex-credit-card-number-tests CreditCard string = "" /* 154-byte string literal not displayed */ // Coordinate represents latitude and longitude regular expression Coordinate string = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?),\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$" // Ref: https://stackoverflow.com/questions/3518504/regular-expression-for-matching-latitude-longitude-coordinates // CSSColor represents css valid color code with hex, rgb, rgba, hsl, hsla etc. Ref: http://www.regexpal.com/97509 CSSColor string = "^(#([\\da-f]{3}){1,2}|(rgb|hsl)a\\((\\d{1,3}%?,\\s?){3}(1|0?\\.\\d+)\\)|(rgb|hsl)\\(\\d{1,3}%?(,\\s?\\d{1,3}%?){2}\\))$" // Date represents regular expression for valid date like: yyyy-mm-dd Date string = "" /* 231-byte string literal not displayed */ // DateDDMMYY represents regular expression for valid date of format dd/mm/yyyy , dd-mm-yyyy etc.Ref: http://regexr.com/346hf DateDDMMYY string = "^(0?[1-9]|[12][0-9]|3[01])[\\/\\-](0?[1-9]|1[012])[\\/\\-]\\d{4}$" // Digits represents regular epxression for validating digits Digits string = "^[+-]?([0-9]*\\.?[0-9]+|[0-9]+\\.?[0-9]*)([eE][+-]?[0-9]+)?$" // Email represents regular expression for email Email string = "" /* 133-byte string literal not displayed */ // Float represents regular expression for finding float number Float string = "^(?:[-+]?(?:[0-9]+))?(?:\\.[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$" // IP represents regular expression for ip address IP string = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" // IPV4 represents regular expression for ip address version 4 IPV4 string = "^([0-9]{1,3}\\.){3}[0-9]{1,3}(\\/([0-9]|[1-2][0-9]|3[0-2]))?$" // IPV6 represents regular expression for ip address version 6 IPV6 string = `` /* 1057-byte string literal not displayed */ // Latitude represents latitude regular expression Latitude string = "^(\\+|-)?(?:90(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\\.[0-9]{1,6})?))$" // Longitude represents longitude regular expression Longitude string = "^(\\+|-)?(?:180(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\\.[0-9]{1,6})?))$" // MacAddress represents regular expression for mac address MacAddress string = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$" // Numeric represents regular expression for numeric Numeric string = "^-?[0-9]+$" // URL represents regular expression for url URL string = "^(?:http(s)?:\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$" // Ref: https://stackoverflow.com/questions/136505/searching-for-uuids-in-text-with-regex // UUID represents regular expression for UUID UUID string = "^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$" // UUID3 represents regular expression for UUID version 3 UUID3 string = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$" // UUID4 represents regular expression for UUID version 4 UUID4 string = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$" // UUID5 represents regular expression for UUID version 5 UUID5 string = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$" )
Variables ¶
This section is empty.
Functions ¶
func AddCustomRule ¶
func AddCustomRule(name string, fn func(field string, rule string, message string, value interface{}, form map[string]interface{}) error)
AddCustomRule help to add custom rules for validator First argument it takes the rule name and second arg a func Second arg must have this signature below fn func(name string, fn func(field string, rule string, message string, value interface{}) error see example in readme: https://github.com/thedevsaddam/govalidator#add-custom-rules
Types ¶
type Float32 ¶
Float32 describes a custom type of built-in float32 data type
func (*Float32) UnmarshalJSON ¶
UnmarshalJSON ...
type Float64 ¶
Float64 describes a custom type of built-in float64 data type
func (*Float64) UnmarshalJSON ¶
UnmarshalJSON ...
type Options ¶
type Options struct { Data interface{} // Data represents structure for JSON body Request *http.Request RequiredDefault bool // RequiredDefault represents if all the fields are by default required or not Rules MapData // Rules represents rules for form-data/x-url-encoded/query params data Messages MapData // Messages represents custom/localize message for rules TagIdentifier string // TagIdentifier represents struct tag identifier, e.g: json or validate etc FormSize int64 //Form represents the multipart forom data max memory size in bytes }
Options describes configuration option for validator
type Validator ¶
type Validator struct {
Opts Options // Opts contains all the options for validator
}
Validator represents a validator with options
func (*Validator) SetDefaultRequired ¶
SetDefaultRequired change the required behavior of fields Default value if false If SetDefaultRequired set to true then it will mark all the field in the rules list as required
func (*Validator) SetTagIdentifier ¶
SetTagIdentifier change the default tag identifier (json) to your custom tag.
func (*Validator) Validate ¶
Validate validate request data like form-data, x-www-form-urlencoded and query params see example in README.md file ref: https://github.com/thedevsaddam/govalidator#example
func (*Validator) ValidateJSON ¶
ValidateJSON validate request data from JSON body to Go struct see example in README.md file