Input validation with comptime rules for Zig. Type-safe validators, chainable rules, detailed error messages.
Validate registration forms, API payloads, or config files in one pass. Each validator returns an optional ValidationError with field name and message.
const ziovalid = @import("ziovalid");
// Validate a registration form — each check returns null on pass
var errors: [10]?ziovalid.ValidationError = .{null} ** 10;
var n: usize = 0;
if (ziovalid.nonEmpty("username", form.username)) |e| { errors[n] = e; n += 1; }
if (ziovalid.alphanumeric("username", form.username)) |e| { errors[n] = e; n += 1; }
if (ziovalid.minLen("password", form.password, 8)) |e| { errors[n] = e; n += 1; }
if (ziovalid.email("email", form.email)) |e| { errors[n] = e; n += 1; }
if (ziovalid.range(u8, "age", 25, 1, 120)) |e| { errors[n] = e; n += 1; }
// Quick boolean helpers for one-liners
if (ziovalid.isEmail("[email protected]")) { /* ok */ }zig fetch --save git+https://github.com/deblasis/ziovalidThen in your build.zig:
const dep = b.dependency("ziovalid", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("ziovalid", dep.module("ziovalid"));Requires Zig 0.16.
nonEmpty(field, value)— reject empty stringsminLen(field, value, min)/maxLen(field, value, max)— length boundsalphanumeric(field, value)/numeric(field, value)/alpha(field, value)— charset checksemail(field, value)— requires@oneOf(field, value, allowed)— whitelistcontains(field, value, substr)/startsWith(field, value, prefix)— substring checksminVal(T, field, value, threshold)/maxVal(T, field, value, threshold)— numeric boundsrange(T, field, value, lo, hi)— inclusive rangeisEmail(value)/isAlphanumeric(value)/isNumeric(value)— quick boolean helpers
- Zig: 0.16.0
- Platforms: Linux, macOS, Windows
- Breaking changes: follows Semantic Versioning. Minor versions add features, patch versions fix bugs.
MIT. Copyright (c) 2026 Alessandro De Blasis.