Search for a command to run...
Last updated June 9, 2026
Ctrovalidate provides 22 atomic validation rules that form the foundation of the validation engine. These rules are zero-dependency and consistent across all platforms (Browser, Node.js, and Edge).
Most rules skip (return true) when the value is empty. This allows "optional but valid" fields — only required and sameAs always execute.
| Skip pattern | Rules affected |
|---|---|
| Never skips | required, sameAs |
null, undefined, "" | min, max, minLength, maxLength, exactLength, between |
Falsy (!value) | email, url, ipAddress, json, phone, creditCard, strongPassword, alpha, alphaNum, alphaDash, alphaSpaces |
Falsy AND not 0 | numeric, integer, decimal |
| Rule | Behavior | Params | Skip |
|---|---|---|---|
required | null, undefined, "", whitespace → fail. false → fail. Booleans pass as-is. | None | Never |
sameAs | Strict equality (===) against target value. Missing param → console.error + fail. | targetValue | Never |
<input name="email" data-ctrovalidate-rules="required" />
<input name="confirm" data-ctrovalidate-rules="required|sameAs:email" />In ctrovalidate-browser, sameAs resolves the other field's current value from the DOM before comparing.
| Rule | Behavior | Params | Skip |
|---|---|---|---|
minLength | String(value).length >= N | N (number) | null, undefined, "" |
maxLength | String(value).length <= N | N (number) | null, undefined, "" |
exactLength | String(value).length === N | N (number) | null, undefined, "" |
between | Dual mode (see below) | min, max | null, undefined, "" |
between — Dual ModeNumber(value) >= min && Number(value) <= max)value.length >= min && value.length <= max)<input name="age" data-ctrovalidate-rules="required|numeric|between:18,120" />
<input name="bio" data-ctrovalidate-rules="between:10,200" />
<!-- bio "Hello" (length 5) → fails; "Hello World" (length 11) → passes -->| Rule | Behavior | Params | Skip |
|---|---|---|---|
numeric | !isNaN(Number(value)) | None | Falsy but not 0 |
integer | Regex /^-?\d+$/ | None | Falsy but not 0 |
decimal | Regex /^-?\d+(\.\d+)?$/ | None | Falsy but not 0 |
min | Number(value) >= N | N (number) | null, undefined, "" |
max | Number(value) <= N | N (number) | null, undefined, "" |
| Rule | Behavior | Params | Skip |
|---|---|---|---|
alpha | Regex /^[a-zA-Z]+$/ | None | Falsy |
alphaNum | Regex /^[a-zA-Z0-9]+$/ | None | Falsy |
alphaDash | Regex /^[a-zA-Z0-9-_]+$/ | None | Falsy |
alphaSpaces | Regex /^[a-zA-Z\s]+$/ | None | Falsy |
email | Simple regex: /^[^\s@]+@[^\s@]+\.[^\s@]+$/ | None | Falsy |
url | Regex: must start with http:// or https:// | None | Falsy |
ipAddress | IPv4 or IPv6 (expanded format with zone ID) | None | Falsy |
phone | International format: + optional, 7-15 digits | None | Falsy |
creditCard | Strips -/spaces, checks digits only, Luhn algorithm | None | Falsy |
json | JSON.parse() then checks typeof === 'object' | None | Falsy |
| Rule | Behavior | Params | Skip |
|---|---|---|---|
strongPassword | ≥8 chars, ≥1 lowercase, ≥1 uppercase, ≥1 digit, ≥1 special (@$!%*?&) | None | Falsy |
Parameters are separated by colons for the rule name, and commas between multiple params:
<input name="age" data-ctrovalidate-rules="required|numeric|between:18,99" />
<input name="price" data-ctrovalidate-rules="required|numeric|min:0|max:1000" />When using schema objects, parameters preserve their types:
const schema = {
age: [
{ name: 'required' },
{ name: 'between', params: [18, 99] },
],
};required|numeric) instead of creating one "monster" custom rule.required first to stop early on empty fields.between:18,99).requiredsameAsminLengthmaxLengthexactLengthbetweennumericintegerdecimalminmaxalphaalphaNumalphaDashalphaSpacesemailurlphoneipAddresscreditCardstrongPasswordjsonFor custom rules and async validation, see Custom Rules and Async Validation.