Validation

Validate and sanitize user input with built-in helpers.

Validation

Validate data structures against a schema-like definition.

  • solidb.validate(data, rules) -> bool, error
    Returns true if valid, or false and an error message.

    Rules:
    • type: "string", "number", "boolean", "table", "email", "uuid"
    • required: boolean
    • min, max: number (for numbers) or length (for strings)
    • matches: regex string
local valid, err = solidb.validate(request.body, {
  name = { type = "string", required = true, min = 3 },
  age = { type = "number", min = 18 },
  email = { type = "email" }
})

if not valid then
  response.status = 400
  return { error = err }
end

Sanitization

  • solidb.sanitize(str) -> string
    Simple wrapper to strip HTML tags.
  • solidb.escape_html(str) -> string
    Convert special characters to HTML entities.