Go Validator

Built-in Is Validators

Validators (Only Is Functions)

IsNotEmpty

Checks if a value is not empty.

Usage Example:

 
validator.CreateValidator(validator.IsNotEmpty, "Value cannot be empty")
 

IsAlphanumeric

Checks if a string contains only alphanumeric characters.

Usage Example:

 
validator.CreateValidator(validator.IsAlphanumeric, "Username must be alphanumeric")
 

IsEmail

Checks if a string is a valid email address.

Usage Example:

 
validator.CreateValidator(validator.IsEmail, "Invalid email address")
 

IsIn(allowedValues ...interface)

Checks if a value is in a predefined list of allowed values.

Usage Example:

 
validator.CreateValidator(validator.IsIn("admin", "user", "guest"), "Value must be one of [admin, user, guest]")
 

IsString

Checks if a value is a string.

Usage Example:

 
validator.CreateValidator(validator.IsString, "Value must be a string")
 

IsNumber

Checks if a value is a number (int or float).

Usage Example:

 
validator.CreateValidator(validator.IsNumber, "Value must be a number")
 

IsInt

Checks if a value is an integer.

Usage Example:

 
validator.CreateValidator(validator.IsInt, "Value must be an integer")
 

IsFloat

Checks if a value is a float.

Usage Example:

 
validator.CreateValidator(validator.IsFloat, "Value must be a float")
 

IsBool

Checks if a value is a boolean.

Usage Example:

 
validator.CreateValidator(validator.IsBool, "Value must be a boolean")
 

IsSlice

Checks if a value is a slice.

Usage Example:

 
validator.CreateValidator(validator.IsSlice, "Value must be a slice")
 

IsMap

Checks if a value is a map.

Usage Example:

 
validator.CreateValidator(validator.IsMap, "Value must be a map")
 

IsURL

Checks if a string is a valid URL.

Usage Example:

 
validator.CreateValidator(validator.IsURL, "Value is not a valid URL")
 

IsUUID

Checks if a string is a valid UUID.

Usage Example:

 
validator.CreateValidator(validator.IsUUID, "Value is not a valid UUID")
 

IsDate

Checks if a string is a valid date in the format YYYY-MM-DD.

Usage Example:

 
validator.CreateValidator(validator.IsDate, "Value is not a valid date (expected format: YYYY-MM-DD)")
 

IsTime

Checks if a string is a valid time in the format HH:MM:SS.

Usage Example:

 
validator.CreateValidator(validator.IsTime, "Value is not a valid time (expected format: HH:MM:SS)")
 

IsCreditCard

Checks if a string is a valid credit card number using the Luhn algorithm.

Usage Example:

 
validator.CreateValidator(validator.IsCreditCard, "Value is not a valid credit card number")
 

IsHexColor

Checks if a string is a valid hexadecimal color code.

Usage Example:

 
validator.CreateValidator(validator.IsHexColor, "Value is not a valid hexadecimal color code")
 

IsJSON

Checks if a string is valid JSON.

Usage Example:

 
validator.CreateValidator(validator.IsJSON, "Value is not valid JSON")
 

IsIP

Checks if a string is a valid IP address (IPv4 or IPv6).

Usage Example:

 
validator.CreateValidator(validator.IsIP, "Value is not a valid IP address")
 

IsAlpha

Checks if a string contains only alphabetic characters.

Usage Example:

 
validator.CreateValidator(validator.IsAlpha, "Value must contain only alphabetic characters")
 

IsAlphaNumeric

Checks if a string contains only alphanumeric characters.

Usage Example:

 
validator.CreateValidator(validator.IsAlphaNumeric, "Value must contain only alphanumeric characters")
 

IsArabic

Checks if a string contains only Arabic characters (including spaces and common Arabic punctuation).

Usage Example:

 
validator.CreateValidator(validator.IsArabic, "Value must contain only Arabic characters")
 

IsAlphaArabic

Checks if a string contains only Arabic and Latin alphabetic characters.

Usage Example:

 
validator.CreateValidator(validator.IsAlphaArabic, "Value must contain only Arabic and Latin alphabetic characters")
 

IsBase64

Checks if a string is valid Base64-encoded data.

Usage Example:

 
validator.CreateValidator(validator.IsBase64, "Value is not valid Base64")
 

IsBase64Image

Checks if a string is valid Base64-encoded image data.

Usage Example:

 
validator.CreateValidator(validator.IsBase64Image, "Value is not a valid Base64 image")
 

On this page