String
Validate strings with length, pattern, and common formats (email, URL, UUID, etc.).
Parameters
- options?:
table- required_error?:
string- Custom required message
- type_error?:
string- Custom invalid type message
- required_error?:
local name = calid:string({
required_error = "Name is required",
type_error = "Name must be a string"
})Options
:default(value)– Specifies a fallback value when the input isnil. Useful for optional fields with defaults.:optional()– Allowsnilas a valid value without causing a validation error.:coerce()– Converts numbers or booleans to strings before validation.:length(n)– Requires the string to be exactlyncharacters long.:min(n)– Sets minimum character length.:max(n)– Sets maximum character length.:startsWith(prefix)– Validates that the string begins with the specified prefix.:endsWith(suffix)– Validates that the string ends with the specified suffix.:includes(substr)– Ensures the string contains the given substr anywhere in its content.:regex(pattern)– Validates the string against a Lua regex pattern.:email()– Validates standard email address formats.:url()– Validates URLs with HTTP/S schemes.:uuid()– Checks that the string is a valid UUID.:nanoid()– Validates NanoID format strings.:cuid()– Validates CUID identifiers.:cuid2()– Validates CUID2 identifiers.:ulid()– Checks for valid ULID strings.:ip()– Accepts IPv4 and IPv6 addresses.:cidr()– Validates CIDR notations (e.g., 192.168.1.0/24).