Skip to content

number

Validates numbers (integers or floats) with optional constraints. DDataParser.number() ensures the input is a number, applies your checkers (min, max, int, refine, etc.) and returns an Either containing either the validated value or a rich DataParserError.

Interactive example

Parameters

  • errorMessage: custom message when the input is not a number.
  • checkers: checkerNumberMin, checkerNumberMax, checkerInt, checkerRefine, etc.
  • coerce: true to convert strings/booleans before validation (via Number(value)). Defaults to false.

Return value

A DataParserNumber with parse, asyncParse, exec, asyncExec, addChecker, clone. parse returns DEither.success<number> if everything passes or DEither.error<DataParserError> with the accumulated issues.

Other examples

Custom checkers

Extended mode

See also

  • date - Parser for dates
  • coerce.* - Coercion functions for various types

Released under the MIT license.