Numeric
Validate that a value is a number, including decimals and negative values.
Validates that a value is a number. Accepts integers, decimals, negative values, and zero. Does not accept whitespace or non-numeric characters.
| Config flag | Type | Description |
|---|
numeric | boolean | When true, requires the value to be numeric. |
const form = useForm({
initialValues: { price: '' },
validationSchema: {
price: { numeric: true },
},
});
import { V } from 'formify-js';
V.numeric();
| Scenario | Message |
|---|
| Value is not a number | Must be a number |
| Value | Result |
|---|
'123' | ✅ Valid |
'12.5' | ✅ Valid |
'-7' | ✅ Valid |
'0' | ✅ Valid |
'12,5' | ❌ Invalid (comma decimal separator not accepted) |
' 123 ' | ❌ Invalid (whitespace) |
- Use
integer when decimals should be rejected.
- Use
decimal when a decimal point is required.