Numeric validators
Numeric validators
numeric
Validates that a field contains a valid numeric value (not a string). The value must already be a number - validators do not parse strings.
Important: Use the autoClean option on numeric/monetary fields to automatically convert strings like "$1,234" into numbers before validation.
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
allowDecimals | boolean | No | true | Whether decimal values are permitted. When false, only integers are valid |
autoFixOptions | ICleanNumberOptions | No | - | Configuration for smartFix suggestions when validation fails |
Auto-fix options:
These options are used by smartFix to suggest fixes for invalid data. They do not affect validation itself.
| Property | Type | Default | Description |
|---|---|---|---|
locale | ILocale | 'en-AU' | Locale for parsing in smartFix suggestions (e.g., 'en-AU', 'de-DE', 'fr-FR') |
stripCurrencySymbols | boolean | true | Whether to strip currency symbols in smartFix |
stripOnlyTheseCurrencies | string[] | 'any' | 'any' | Which currency symbols to strip. 'any' strips all Unicode currency symbols |
currencyPosition | 'prefix' | 'suffix' | 'both' | 'both' | Where currency symbols may appear |
decimalHandling | 'drop' | 'round' | 'ceil' | 'floor' | 'round' | How to handle decimals in smartFix |
decimalPlaces | number | 0 | Number of decimal places for smartFix |
{
type: 'numeric',
allowDecimals: false,
autoFixOptions: {
stripCurrencySymbols: true,
decimalHandling: 'round',
decimalPlaces: 2,
locale: 'en-AU'
}
}Note: For numeric and monetary fields, this validator is automatically added with sensible defaults. You only need to specify it if you want to customize the behavior.
min
Validates that a numeric field meets a minimum value threshold. The value must already be a number.
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
value | number | Yes | - | Minimum allowed value (inclusive) |
{
type: 'min',
value: 18,
message: 'Age must be at least 18'
}max
Validates that a numeric field does not exceed a maximum value threshold. The value must already be a number.
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
value | number | Yes | - | Maximum allowed value (inclusive) |
{
type: 'max',
value: 100,
message: 'Discount cannot exceed 100%'
}range
Validates that a numeric field falls within a specified range. Combines min and max validation in a single rule. The value must already be a number.
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
min | number | Yes | - | Minimum allowed value (inclusive) |
max | number | Yes | - | Maximum allowed value (inclusive) |
{
type: 'range',
min: 0,
max: 100,
message: 'Score must be between 0 and 100'
}How Numeric Validation Works
The Flow
- CSV/Excel Import: Data comes in as strings (e.g., "$1,234.56")
- CleanNumbers Transformer: Converts strings to numbers (if
autoCleanenabled on field) - Numeric Validator: Checks if value is a number (not a string)
- Min/Max/Range Validators: Check numeric constraints
Key Points
- Validators only check numbers: They don't parse strings. If you pass a string like "1234", validation fails.
- Use autoClean for automatic conversion: Enable
autoCleanon numeric/monetary fields to automatically convert strings to numbers. - SmartFix for manual fixes: When validation fails, smartFix uses
autoFixOptionsto suggest fixes.
Example
{
type: 'numeric',
key: 'price',
label: 'Price',
order: 0,
autoClean: { // Automatically converts strings to numbers
stripCurrencySymbols: true,
decimalPlaces: 2,
decimalHandling: 'round',
locale: 'en-AU'
},
validators: [
{ type: 'numeric', allowDecimals: true }, // Checks if it's a number
{ type: 'min', value: 0 }, // Checks if >= 0
{ type: 'max', value: 10000 } // Checks if <= 10000
]
}Flow:
- User uploads CSV with "$1,234.56"
- CleanNumbers transformer converts to
1234.56(number) - Numeric validator passes (it's a number)
- Min validator passes (1234.56 is at least 0)
- Max validator passes (1234.56 is at most 10000)
- Valid