Ivandt logo

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.

PropertyTypeRequiredDefaultDescription
allowDecimalsbooleanNotrueWhether decimal values are permitted. When false, only integers are valid
autoFixOptionsICleanNumberOptionsNo-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.

PropertyTypeDefaultDescription
localeILocale'en-AU'Locale for parsing in smartFix suggestions (e.g., 'en-AU', 'de-DE', 'fr-FR')
stripCurrencySymbolsbooleantrueWhether to strip currency symbols in smartFix
stripOnlyTheseCurrenciesstring[] | '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
decimalPlacesnumber0Number 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.

PropertyTypeRequiredDefaultDescription
valuenumberYes-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.

PropertyTypeRequiredDefaultDescription
valuenumberYes-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.

PropertyTypeRequiredDefaultDescription
minnumberYes-Minimum allowed value (inclusive)
maxnumberYes-Maximum allowed value (inclusive)
{
  type: 'range',
  min: 0,
  max: 100,
  message: 'Score must be between 0 and 100'
}

How Numeric Validation Works

The Flow

  1. CSV/Excel Import: Data comes in as strings (e.g., "$1,234.56")
  2. CleanNumbers Transformer: Converts strings to numbers (if autoClean enabled on field)
  3. Numeric Validator: Checks if value is a number (not a string)
  4. 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 autoClean on numeric/monetary fields to automatically convert strings to numbers.
  • SmartFix for manual fixes: When validation fails, smartFix uses autoFixOptions to 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:

  1. User uploads CSV with "$1,234.56"
  2. CleanNumbers transformer converts to 1234.56 (number)
  3. Numeric validator passes (it's a number)
  4. Min validator passes (1234.56 is at least 0)
  5. Max validator passes (1234.56 is at most 10000)
  6. Valid