Integer
Validate that a value is a whole number without decimals.
Validates that a value is an integer — a whole number with no decimal or fractional part. Negative integers and zero are accepted.
| Config flag | Type | Description |
|---|
integer | boolean | When true, requires the value to be an integer. |
const form = useForm({
initialValues: { quantity: '' },
validationSchema: {
quantity: { integer: true },
},
});
import { V } from 'formify-js';
V.integer();
| Scenario | Message |
|---|
| Value is not a whole number | Must be an integer |
| Value | Result |
|---|
'42' | ✅ Valid |
'-3' | ✅ Valid |
'0' | ✅ Valid |
'4.5' | ❌ Invalid |
'4.0' | ❌ Invalid (decimal notation rejected) |
- Combine with
min / max / between to constrain the accepted range.
- A value like
4.0 fails because the decimal point is present; the check is on the literal value, not Number.isInteger coercion.