Validate

Library
Updated 2 months ago · v1.3.7
i

Shared Module

Build validation chains to assert value types, ranges, and custom constraints.

validate

Creates a new validation chain for a value.

lua
local name = validate(playerName).string(32).min(1).done()
local count = validate(amount).number().min(1).max(100).done()

Methods

MethodParametersDescription
.string(len?)len: number — optional max lengthAssert value is a string
.number()—Assert value is a number
.boolean()—Assert value is a boolean
.min(min)min: numberMinimum value (number) or minimum length (string)
.max(max)max: numberMaximum value (number) or maximum length (string)
.refine(fn, err?)fn: function(value) → boolean, err: stringCustom validation function
.default(value)value: anyUse this value if the input is nil
.done()—Finalize and return the raw value

The chain can also be called directly — validate(x).string()() is equivalent to .done().

Example

lua
local function processPayment(data)
    local amount = validate(data.amount).number().min(1).max(10000).done()
    local note = validate(data.note).string(200).default('').done()
    local rush = validate(data.rush).boolean().default(false).done()
    
    -- Custom validation
    local code = validate(data.code).string().refine(function(v)
        return #v == 6
    end, 'Code must be 6 characters').done()
end
Was this page helpful?
This page was last updated on 12 March 2026
DIRKSCRIPTS
All you need for your FiveM server.10% off your first order

Unsubscribe any time.

Copyright © 2026 DirkScripts. Not affiliated with or endorsed by Rockstar North or Take-Two Interactive.