isHex
Checks if a string is a valid hex string
Loading...
Checks if a string is a valid hex string
Checks if a string is a valid hex string.
import "github.com/ChefBingbong/viem-go/utils/data"import "github.com/ChefBingbong/viem-go/utils/data"
// Valid hex stringvalid := data.IsHex("0x0102")// true
// Valid empty hexvalid = data.IsHex("0x")// true
// Invalid (no prefix)valid = data.IsHex("0102")// false
// Invalid characters (strict mode)valid = data.IsHex("0xgg", data.IsHexOptions{Strict: true})// false
// Valid prefix only (non-strict mode)valid = data.IsHex("0xgg", data.IsHexOptions{Strict: false})// truebooltrue if the string is a valid hex string, false otherwise.
stringThe string to validate.
valid := data.IsHex("0x0102")booltrueIf true, validates that the string contains only valid hex characters (0-9, a-f, A-F). If false, only checks for the 0x prefix.
// Strict mode (default) - validates hex charactersvalid := data.IsHex("0x0102", data.IsHexOptions{Strict: true})// true
valid = data.IsHex("0xgg", data.IsHexOptions{Strict: true})// false
// Non-strict mode - only checks prefixvalid = data.IsHex("0xgg", data.IsHexOptions{Strict: false})// trueAlias for IsHex with Strict: true:
valid := data.IsHexString("0x0102")
// true