Skip to content

deblasis/ziovalid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ziovalid

Input validation with comptime rules for Zig. Type-safe validators, chainable rules, detailed error messages.

The pitch

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 */ }

Install

zig fetch --save git+https://github.com/deblasis/ziovalid

Then 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.

API

  • nonEmpty(field, value) — reject empty strings
  • minLen(field, value, min) / maxLen(field, value, max) — length bounds
  • alphanumeric(field, value) / numeric(field, value) / alpha(field, value) — charset checks
  • email(field, value) — requires @
  • oneOf(field, value, allowed) — whitelist
  • contains(field, value, substr) / startsWith(field, value, prefix) — substring checks
  • minVal(T, field, value, threshold) / maxVal(T, field, value, threshold) — numeric bounds
  • range(T, field, value, lo, hi) — inclusive range
  • isEmail(value) / isAlphanumeric(value) / isNumeric(value) — quick boolean helpers

Compatibility

  • Zig: 0.16.0
  • Platforms: Linux, macOS, Windows
  • Breaking changes: follows Semantic Versioning. Minor versions add features, patch versions fix bugs.

License

MIT. Copyright (c) 2026 Alessandro De Blasis.

About

Input validation with comptime rules for Zig. Type-safe validators, chainable rules, detailed error messages.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

 
 
 

Contributors

Languages