Creates a new VineNumber instance with optional configuration.
Optionaloptions: Partial<FieldOptions> & { strict?: boolean }Field options like bail mode, nullability and strict mode
Optionalvalidations: Validation<any>[]Initial set of validations to apply
Define the input type of the schema for TypeScript inference
The output value type of the field after validation. The property points to a type only and not the real value.
Type marker for camelCase output type inference
OptionaldataThe validation to use for validating the schema data type. Using a data type validator guards custom rules to only run when the data type validation passes.
StaticrulesStatic collection of all available validation rules for numbers
The subtype identifier for the literal schema field
Unique name identifier for union type resolution
Define a method to parse the input value. The method is invoked before any validation and hence you must perform type-checking to know the value you are working it.
Adds a validation rule to the schema's validation chain. Rules are executed in the order they are added.
The validation rule or rule builder to add
This schema instance for method chaining
Enable/disable bail mode for this field. In bail mode, field validations stop after the first error.
Whether to enable bail mode
This schema instance for method chaining
Mark the field under validation as optional. An optional field allows both null and undefined values.
Mark the field under validation to be null. The null value will be written to the output as well.
If optional and nullable are used together, then both undefined
and null values will be allowed.
Apply transform on the final validated value. The transform method may convert the value to any new datatype.
Compiles the literal schema type into a compiler node. This method transforms the schema definition into a format that the validation compiler can process.
Name of the property being compiled
Reference store for the compiler
Parser options including camelCase conversion
Compiled literal node with subtype information
Type checker function to determine if a value can be converted to a number. Required for "unionOfTypes" functionality.
The value to check
True if the value can be converted to a valid number
Enforce a minimum value for the number input.
The minimum allowed value
This number schema instance for method chaining
Enforce a maximum value for the number input.
The maximum allowed value
This number schema instance for method chaining
Enforce value to be within the range of minimum and maximum values.
Tuple containing [min, max] values
This number schema instance for method chaining
Enforce the value be a positive number
Enforce the value be a negative number
Enforce the value be a positive number or zero
Enforce the value be a negative number or zero
Enforce the value to have fixed or range of decimal places
Enforce the value to be an integer (aka without decimals)
Clones the VineNumber schema type. The applied options and validations are copied to the new instance
VineNumber represents a numeric value in the validation schema. It accepts both string and number inputs and converts them to numbers, with comprehensive validation for ranges, decimals, and sign constraints.
Example