validators

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 11 Imported by: 0

README

Validation Package

The package provides a set of validation utilities to check various conditions in data fields. These validators can be used to ensure data integrity and enforce specific requirements in your Go applications, making use only of native libraries to perform the validations.

Objective

The aim is to offer a simple and flexible way to perform data validation in Go applications in a customizable manner. By providing a set of validators, developers can easily incorporate data validation logic into their applications to ensure data consistency and meet specific validation requirements, without the need to write validation code from scratch, customizing validations according to the project's needs.

Installation

To use the package in your Go projects, type the following command in your terminal:

go get github.com/dariomatias-dev/go-validators

Order of Validators

Validators should be organized following the following order: presence validator, type validator, and value validators. They should follow this order because otherwise, an error may occur if the sent value is not accepted by a validator that is placed later, even if it is a valid value.

This organization ensures that basic requirements, such as presence and type, are validated first before more specific validations about the value itself. By validating in this order, we can detect any potential errors early in the process, leading to a more robust and error-free validation system.

Just as there are no reasons to check if the value is of a specific type in value validators, which require the sent value to be of a certain type, as there are dedicated validators for this purpose, thus reducing the number of checks, making the validation process more efficient.

How to Use

To use the package, first import it into your project with the following import statement:

import "github.com/dariomatias-dev/go-validators"

I advise you to give it an alias to make package usage simpler and more efficient, like this:

import v "github.com/dariomatias-dev/go-validators"
Functionality of Validators

The validators have been created based on configurable functions, where the first set of parameters within the first pair of parentheses is used to configure the behavior of the validator, while the second set of parentheses receives the value to be validated. In the table of validators-available, it's referenced which validators require which value to be provided in order to perform validation.

Usage

To use the validations, use v. followed by the desired validation. In the first parenthesis, provide what is being requested, and if you don't want the default error message, insert the desired message afterwards. The validators will return two values: the first will be the error message if the provided value did not pass validation, and the second will be a boolean value indicating whether the validations should be halted or not. The second value is used in situations where, if the value did not pass the validator, subsequent validations cannot be executed because they will result in an error.

Validations can be performed in three distinct ways: individually, or within a json.

Validate Individual Value

A single validator is applied to a specific value.

Examples:

// Success
value := 4

err, _ := v.Min(3)(value) // nil, false
if err != nil {
    fmt.Println(err)
    return
}

// Error
value = 2

err, _ = v.Min(3)(value)  // The minimum value is 3, but it received 2, false
if err != nil {
    fmt.Println(err)
    return
}
Validate JSON

Validates the provided JSON based on the validators defined for each field, returning an error if there is an inconsistency, or assigning the values from the JSON to the provided struct if there are no errors.

Examples:

type UserModel struct {
    Name  string `json:"name"  validates:"required;isString;minLength=3;maxLength=20"`
    Age   int    `json:"age"   validates:"required;isInt;min=18;max=100"`
    Email string `json:"email" validates:"required;email"`
}
user := UserModel{}

json := `{
    "name":  "Name",
    "age":   18,
    "email": "emailexample@gmail.com"
}`

// Success
err := Validate(&user, json)           // Output: nil
if err != nil {
    fmt.Println(err)
    return
}

// Error
json := `{
    "name":  "Name",
    "age":   16,
    "email": "emailexample@gmail.com"
}`
err := Validate(&user, json)           // Output: {"age":["The minimum value is 18, but it received 16."]}
if err != nil {
    fmt.Println(err)
    return
}
Validators Available
Validator Type Input Value Type
Required Presence
  • Error message
any
IsString Type
  • Error message
string
IsNumber Type
  • Error message
int | float
IsInt Type
  • Error message
int
IsFloat Type
  • Error message
float
IsBool Type
  • Error message
bool
IsArray Type
  • Field validators*
  • Error message
slice | array
IsNullString Type
  • Error message
nil | string
IsNullNumber Type
  • Error message
nil | int | float
IsNullInt Type
  • Error message
nil | int
IsNullFloat Type
  • Error message
nil | float
IsNullBool Type
  • Error message
nil | bool
IsNullArray Type
  • Field validators*
  • Error message
nil | slice | array
Email Value
  • Minimum value*
  • Error messages
    • Invalid email
    • Value is not string
string
Password Value
  • Error message
string
Min Value
  • Minimum value*
  • Error message
int | int32 | int64 | float32 | float64
Max Value
  • Maximum value*
  • Error message
int | int32 | int64 | float32 | float64
Length Value
  • Size*
  • Error message
string | slice | array
MinLength Value
  • Minimum size*
  • Error message
string | slice | array
MaxLength Value
  • Maximum size*
  • Error message
string | slice | array
IsAlpha Value
  • Error message
string
IsAlphaNum Value
  • Error message
string
IsAlphaSpace Value
  • Error message
string
IsAlphaNumSpace Value
  • Error message
string
StartsWith Value
  • Starts with*
  • Error message
string
StartsNotWith Value
  • Starts not with*
  • Error message
string
EndsWith Value
  • Ends with*
  • Error message
string
EndsNotWith Value
  • Ends not with*
  • Error message
string
Regex Value
  • Regex*
  • Error message
string
Url Value
  • Error message
string
Uuid Value
  • Version (Default Version 5)
  • Error message
string
OneOf Value
  • Options*
  • Error message
string
Custom Value
  • Custom validator*
any
All entries marked with (*) are mandatory.

Donations

Help maintain the project with donations.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(
	s any,
	data string,
) error

Validates the provided JSON based on the validators defined for each field.

Parameters:

  • s (any): pointer to a struct.
  • data (string): the JSON to be validated.

Usage examples:

type UserModel struct {
    Name  string `json:"name"  validates:"required;isString;minLength=3;maxLength=20"`
    Age   int    `json:"age"   validates:"required;isInt;min=18;max=100"`
    Email string `json:"email" validates:"required;email"`
}
user := UserModel{}

json := `{
    "name":  "Name",
    "age":   18,
    "email": "emailexample@gmail.com"
}`

// Success
err := Validate(&user, json)           // Output: nil
if err != nil {
    fmt.Println(err)
    return
}

// Error
json := `{
    "name":  "Name",
    "age":   16,
    "email": "emailexample@gmail.com"
}`
err := Validate(&user, json)           // Output: {"age":["The minimum value is 18, but it received 16."]}
if err != nil {
    fmt.Println(err)
    return
}

Types

type Validator

type Validator func(value any) (
	err error,
	abortValidation bool,
)

A function that takes a value to be validated and returns an error message along with a stop indicator for further validations. If the validation is successful, the error message should be nil and the stop indicator should be false. Otherwise, an error message is returned along with a boolean indicating whether to stop subsequent validations or not.

func Email

func Email(
	errorMessages ...string,
) Validator

Checks if the value is a validated email.

Configuration parameters:

1. errorMessages (optional):

  • Invalid email.
  • value is not string.

Input value (string): value to be validated.

Usage examples:

value := "emailexample@gmail.com"
v.Email()(value)           // Output: nil, false

value = "emailexample"
v.Email()(value)           // Output: [error message], false
v.Email("error")(value)    // Output: "error", false
v.Email("", "error2")(nil) // Output: "error2", false

func EndsNotWith added in v0.1.1

func EndsNotWith(
	endsNotWith string,
	errorMessage ...string,
) Validator

Checks if the value does not end with a certain sequence.

Configuration parameters:

1. endsNotWith(string): character sequence that the value should not end with.

2. errorMessage (string): custom error message (optional).

Input value (string): value to be validated.

Usage examples:

value := "message"
v.EndsNotWith("mes")(value)          // Output: nil, false

v.EndsNotWith("age")(value)          // Output: [error message], false
v.EndsNotWith("age", "error")(value) // Output: "error", false

func EndsWith added in v0.1.1

func EndsWith(
	endsWith string,
	errorMessage ...string,
) Validator

Checks whether the value ends with a given string.

Configuration parameters:

1. endsWith(string): character sequence that the value must start with.

2. errorMessage (string): custom error message (optional).

Input value (string): value to be validated.

Usage examples:

value := "message"
v.EndsWith("age")(value)          // Output: nil, false

value := "send message"
v.EndsWith("end")(value)          // Output: [error message], false
v.EndsWith("end", "error")(value) // Output: "error", false

func IsAlpha

func IsAlpha(
	errorMessage ...string,
) Validator

Checks if the value contains only letters.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (string): value to be validated.

Usage examples:

value := "abcABC"
v.IsAlpha()(value)     // Output: nil, false

value = "abcABC "
v.IsAlpha()(value)     // Output: [error message], false

value = "abcABC0123!@"
v.IsAlpha()(value)     // Output: [error message], false

func IsAlphaNum added in v0.2.0

func IsAlphaNum(
	errorMessage ...string,
) Validator

Checks if the value contains only letters and numbers.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (string): value to be validated.

Usage examples:

value := "abcABC"
v.IsAlpha()(value)     // Output: nil, false

value = "abcABC "
v.IsAlpha()(value)     // Output: [error message], false

value = "abcABC012!@"
v.IsAlpha()(value)     // Output: [error message], false

func IsAlphaNumSpace added in v0.2.0

func IsAlphaNumSpace(
	errorMessage ...string,
) Validator

Checks if the value contains only letters, numbers and spaces.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (string): value to be validated.

Usage examples:

value := "abcABC"
v.IsAlphaNumSpace()(value) // Output: nil, false

value = "abcABC "
v.IsAlphaNumSpace()(value) // Output: nil, false

value = "abcABC012!@"
v.IsAlphaNumSpace()(value) // Output: [error message], false

func IsAlphaSpace

func IsAlphaSpace(
	errorMessage ...string,
) Validator

Checks if the value contains only letters and spaces.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (string): value to be validated.

Usage examples:

value := "abcABC"
v.IsAlphaSpace()(value) // Output: nil, false

value = "abcABC "
v.IsAlphaSpace()(value) // Output: nil, false

value = "abcABC0123!@"
v.IsAlphaSpace()(value) // Output: [error message], false

func IsArray

func IsArray(
	validators []Validator,
	errorMessage ...string,
) Validator

Checks if the value is a valid array.

Configuration parameters:

1. validators ([]Validator): validators that will be applied to each value in the array.

2. errorMessage (string): custom error message (optional).

Input value (slice | array): value to be validated.

Usage examples:

value1 := []string{""}
IsArray(
	[]Validator{
		IsString(),
	},
)(value1)               // Output: nil, false

value2 := [1]string{""}
IsArray(
	[]Validator{
		IsString(),
	},
)(value2)               // Output: nil, false

value3 := ""
IsArray(
	[]Validator{
		IsString(),
	},
)(value3)               // Output: [error message], true

value4 := nil
IsNullArray(
	[]Validator{
		IsString(),
	},
)(value4)               // Output: [error message], true

func IsBool

func IsBool(
	errorMessage ...string,
) Validator

Checks if the value is a boolean.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (bool): Value to be validated.

Usage examples:

value1 := true
v.IsBool()(value1)        // Output: nil, false

value2 := nil
v.IsBool()(value2)        // Output: [error message], true

value3 := 0
v.IsBool()(value3)        // Output: [error message], true
v.IsBool("error")(value3) // Output: "error", true

func IsFloat

func IsFloat(
	errorMessage ...string,
) Validator

Checks if the value is a number or null.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (float): value to be validated.

Usage examples:

value2 := 1.0
v.IsFloat()(value2)        // Output: nil, false

value1 := 1
v.IsFloat()(value1)        // Output: [error message], true

value3 := nil
v.IsFloat()(value3)        // Output: [error message], true

value4 := ""
v.IsFloat()(value4)        // Output: [error message], true
v.IsFloat("error")(value4) // Output: "error", true

func IsInt

func IsInt(
	errorMessage ...string,
) Validator

Checks if the value is a number or null.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (int): value to be validated.

Usage examples:

value1 := 1
v.IsInt()(value1)        // Output: nil, false

value3 := nil
v.IsInt()(value3)        // Output: [error message], true

value2 := 1.0
v.IsInt()(value2)        // Output: [error message], true

value4 := ""
v.IsInt()(value4)        // Output: [error message], true
v.IsInt("error")(value4) // Output: "error", true

func IsNullArray

func IsNullArray(
	validators []Validator,
	errorMessage ...string,
) Validator

Checks if the value is a valid array or null.

Configuration parameters:

1. validators ([]Validator): validators that will be applied to each value in the array.

2. errorMessage (string): custom error message (optional).

Input value (nil | slice | array): value to be validated.

Usage examples:

value1 := nil
IsNullArray(
	[]Validator{
		IsString(),
	},
)(value1)               // Output: nil, true

value2 := []string{""}
IsNullArray(
	[]Validator{
		IsString(),
	},
)(value2)               // Output: nil, false

value3 := [1]string{""}
IsNullArray(
	[]Validator{
		IsString(),
	},
)(value3)               // Output: nil, false

value4 := ""
IsNullArray(
	[]Validator{
		IsString(),
	},
)(value4)               // Output: [error message], true

func IsNullBool

func IsNullBool(
	errorMessage ...string,
) Validator

Checks if the value is a boolean or null.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (nil | bool): Value to be validated.

Usage examples:

value1 := true
v.IsNullBool()(value1)        // Output: nil, false

value2 := nil
v.IsNullBool()(value2)        // Output: nil, true

value3 := 0
v.IsNullBool()(value3)        // Output: [error message], true
v.IsNullBool("error")(value3) // Output: "error", true

func IsNullFloat

func IsNullFloat(
	errorMessage ...string,
) Validator

Checks if the value is a number or null.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (nil | float): value to be validated.

Usage examples:

value1 := nil
v.IsNullFloat()(value1)        // Output: nil, true

value2 := 1.0
v.IsNullFloat()(value2)        // Output: nil, false

value3 := 1
v.IsNullFloat()(value3)        // Output: [error message], true

value4 := ""
v.IsNullFloat()(value4)        // Output: [error message], true
v.IsNullFloat("error")(value4) // Output: "error", true

func IsNullInt

func IsNullInt(
	errorMessage ...string,
) Validator

Checks if the value is a number or null.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (nil | int): value to be validated.

Usage examples:

value1 := nil
v.IsNullInt()(value1)        // Output: nil, true

value2 := 1
v.IsNullInt()(value2)        // Output: nil, false

value3 := 1.0
v.IsNullInt()(value3)        // Output: [error message], true

value4 := ""
v.IsNullInt()(value4)        // Output: [error message], true
v.IsNullInt("error")(value4) // Output: "error", true

func IsNullNumber

func IsNullNumber(
	errorMessage ...string,
) Validator

Checks if the value is a number or null.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (nil | number): value to be validated.

Usage examples:

value1 := nil
v.IsNullNumber()(value1)        // Output: nil, true

value2 := 1
v.IsNullNumber()(value2)        // Output: nil, false

value3 := 1.0
v.IsNullNumber()(value3)        // Output: nil, false

value4 := ""
v.IsNullNumber()(value4)        // Output: [error message], true
v.IsNullNumber("error")(value4) // Output: "error", true

func IsNullString

func IsNullString(
	errorMessage ...string,
) Validator

Checks if the value is a string or null.

Configuration parameters:

  1. errorMessage (string): custom error message (optional).

Input value (nil | string): value to be validated.

Usage examples:

value1 := nil
v.IsNullString()(value1)        // Output: nil, true

value2 := "Name"
v.IsNullString()(value2)        // Output: nil, false

value3 := 0
v.IsNullString()(value3)        // Output: [error message], true
v.IsNullString("error")(value3) // Output: "error", true

func IsNumber

func IsNumber(
	errorMessage ...string,
) Validator

Checks if the value is a number.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (number): value to be validated.

Usage examples:

value1 := 1
v.IsNumber()(value1)        // Output: nil, false

value2 := 1.0
v.IsNumber()(value2)        // Output: nil, false

value3 := nil
v.IsNumber()(value3)        // Output: [error message], true

value4 := ""
v.IsNumber()(value4)        // Output: [error message], true
v.IsNumber("error")(value4) // Output: "error", true

func IsString

func IsString(
	errorMessage ...string,
) Validator

Checks if the value is a string.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (string): value to be validated.

Usage examples:

value1 := "Name"
v.IsString()(value1)        // Output: nil, false

value2 := nil
v.IsString()(value2)        // Output: [error message], true

value3 := 0
v.IsString()(value3)        // Output: [error message], true
v.IsString("error")(value3) // Output: "error", true

func Length added in v0.2.0

func Length(
	length any,
	errorMessage ...string,
) Validator

Checks if a string/slice/array has the specified length.

Configuration parameters:

1. length (int): length that the value must have.

2. errorMessage (string): custom error message (optional).

Input value (string | slice | array): value to be validated.

Usage examples:

String

value := "Name"
v.Length(4)(value)               // Output: nil, false

v.Length(3)(value)               // Output: [error message], false
v.Length(3, "error")(value)      // Output: "error", false

Slice

value := []string{"Name", "is"}
v.Length(2)(value)               // Output: nil, false

v.Length(1)(value)               // Output: [error message], false
v.Length(1, "error")(value)      // Output: "error", false

Array

value := [2]string{"Name", "is"}
v.Length(2)(value)               // Output: nil, false

v.Length(1)(value)               // Output: [error message], false
v.Length(1, "error")(value)      // Output: "error", false

func Max

func Max(
	max any,
	errorMessage ...string,
) Validator

Checks if the value is greater than the specified maximum value.

Configuration parameters:

1. max(int | int32 | int64 | float32 | float64): maximum value that the value must have.

2. errorMessage (string): custom error message (optional).

Input value (int | int32 | int64 | float32 | float64): value to be validated.

Usage examples:

value := 3
v.Max(5)(value)          // Output: nil, false

value := 6
v.Max(5)(value)          // Output: [error message], false
v.Max(5, "error")(value) // Output: "error", false

func MaxLength

func MaxLength(
	maxLength any,
	errorMessage ...string,
) Validator

Checks if a string/slice/array has the specified maximum length.

Configuration parameters:

1. maxLength (int): maximum length that the string must have.

2. errorMessage (string): custom error message (optional).

Input value (string | slice | array): value to be validated.

Usage examples:

String

value := "Name"
v.MaxLength(5)(value)            // Output: nil, false

v.MaxLength(3)(value)            // Output: [error message], false
v.MaxLength(3, "error")(value)   // Output: "error", false

Slice

value := []string{"Name", "is"}
v.MaxLength(3)(value)            // Output: nil, false

v.MaxLength(1)(value)            // Output: [error message], false
v.MaxLength(1, "error")(value)   // Output: "error", false

Array

value := [2]string{"Name", "is"}
v.MaxLength(3)(value)            // Output: nil, false

v.MaxLength(1)(value)            // Output: [error message], false
v.MaxLength(1, "error")(value)   // Output: "error", false

func Min

func Min(
	min any,
	errorMessage ...string,
) Validator

Checks if the value is less than the specified minimum value.

Configuration parameters:

1. min(int | int32 | int64 | float32 | float64): minimum value that the value must have.

2. errorMessage (string): custom error message (optional).

Input value (int | int32 | int64 | float32 | float64): value to be validated.

Usage examples:

value := 6
v.Min(5)(value)          // Output: nil, false

value := 3
v.Min(5)(value)          // Output: [error message], false
v.Min(5, "error")(value) // Output: "error", false

func MinLength

func MinLength(
	minLength any,
	errorMessage ...string,
) Validator

Checks if a string/slice/array has the specified minimum length.

Configuration parameters:

1. minLength (int): minimum length that the value must have.

2. errorMessage (string): custom error message (optional).

Input value (string | slice | array): value to be validated.

Usage examples:

String

value := "Name"
v.MinLength(3)(value)            // Output: nil, false

v.MinLength(5)(value)            // Output: [error message], false
v.MinLength(5, "error")(value)   // Output: "error", false

Slice

value := []string{"Name", "is"}
v.MinLength(1)(value)            // Output: nil, false

v.MinLength(3)(value)            // Output: [error message], false
v.MinLength(3, "error")(value)   // Output: "error", false

Array

value := [2]string{"Name", "is"}
v.MinLength(1)(value)            // Output: nil, false

v.MinLength(3)(value)            // Output: [error message], false
v.MinLength(3, "error")(value)   // Output: "error", false

func OneOf added in v0.1.1

func OneOf(
	options any,
	errorMessage ...string,
) Validator

Checks if the value is within certain options.

Configuration parameters:

1. options (slice | array): value options.

2. errorMessage (string): custom error message (optional).

Input value (string | int | float64): value to be validated.

Usage examples:

options := []string{"one", "two", "three"}
value := "three"
v.OneOf(options)(value)                    // Output: nil, false

value = "four"
v.OneOf(options)(value)                    // Output: [error message], false
v.OneOf(options, "error")(value)           // Output: "error", false

func Password

func Password(
	errorMessage ...string,
) Validator

Checks whether the value contains lowercase and uppercase letters, numbers and special characters.

Configuration parameters:

1. errorMessage (string): custom error message.

Input value (string): value to be validated.

Usage examples:

value := "abcABC0123!@"
v.Password()(value)        // Output: nil, false

value = "abc"
v.Password()(value)        // Output: [error message], false
v.Password("error")(value) // Output: "error", false

func Regex

func Regex(
	regex string,
	errorMessage string,
) Validator

Checks if the value meets the given regex.

Configuration parameters:

1. regex (string): regex that will be used to validate value.

2. errorMessage (string): custom error message.

Input value (string): value to be validated.

Usage examples:

regex := "[A-Z]"
errorMessage := "The value must be in capital letters"

value := "ABC"
v.Regex(regex, errorMessage)(value)                    // Output: nil, false

value = "abc"
v.Regex(regex, errorMessage)(value)                    // Output: The value must be in capital letters, false

func Required added in v0.2.0

func Required(
	errorMessage ...string,
) Validator

Checks if the value was provided.

Configuration parameters:

1. errorMessage (string): custom error message (optional).

Input value (any): value to be validated.

Usage examples:

value1 := "Name"
v.Required()(value1) // Output: nil, false

value2 := nil
v.Required()(value2) // Output: [error message], true

func StartsNotWith added in v0.1.1

func StartsNotWith(
	startsNotWith string,
	errorMessage ...string,
) Validator

Checks if the value does not start with a certain sequence.

Configuration parameters:

1. startWith(string): character sequence that the value should not start with.

2. errorMessage (string): custom error message (optional).

Input value (string): value to be validated.

Usage examples:

value := "message"
v.StartsNotWith("es")(value)            // Output: nil, false

value := "send message"
v.StartsNotWith("send")(value)          // Output: [error message], false
v.StartsNotWith("send", "error")(value) // Output: "error", false

func StartsWith added in v0.1.1

func StartsWith(
	startWith string,
	errorMessage ...string,
) Validator

Checks if the value starts with a given sequence.

Configuration parameters:

1. startWith(string): character sequence that the value must start with.

2. errorMessage (string): custom error message (optional).

Input value (string): value to be validated.

Usage examples:

value := "message"
v.StartsWith("mes")(value)          // Output: nil, false

value := "send message"
v.StartsWith("end")(value)          // Output: [error message], false
v.StartsWith("end", "error")(value) // Output: "error", false

func Url added in v0.2.0

func Url(
	errorMessage ...string,
) Validator

Checks if the value is a valid Url.

Configuration parameters:

1. errorMessage (string): custom error message.

Input value (string): value to be validated.

Usage examples:

value := "golang.org"
v.Url()(value)        // Output: nil, false

value = "golang"
v.Url()(value)        // Output: [error message], false
v.Url("error")(value) // Output: "error", false

func Uuid added in v0.2.0

func Uuid(
	version int,
	errorMessage ...string,
) Validator

Checks if the value is a valid UUID.

Configuration parameters:

1. version (int): UUID version.

2. errorMessage (string): custom error message.

Input value (string): value to be validated.

Usage examples:

value := "f47ac10b-58cc-4372-a567-0e02b2c3d479"
v.Uuid(4)(value)          // Output: nil, false

v.Uuid(3)(value)          // Output: [error message], false
v.Uuid(3, "error")(value) // Output: "error", false

value = "00"
v.Uuid(3)(value)          // Output: [error message], false
v.Uuid(3, "error")(value) // Output: "error", false

Jump to

Keyboard shortcuts

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