📦
Schema
  • Getting Started
  • Documents
    • Basics
      • Extend
    • Any
      • Label
      • Default
      • Required
      • Pipe
      • Validate
    • Array
      • Length
      • Max
      • Min
      • Items
    • Boolean
    • Date
      • Max
      • Min
    • Number
      • Max
      • Min
      • Multiple
      • Integer
      • Port
      • Positive
      • Precision
    • Object
      • Length
      • Max
      • Min
      • Keys
    • String
      • Alphanum
      • Credit Card
      • Email
      • Enum
      • IP Address
      • Length
      • Max
      • Min
      • Numeral
      • Regex
      • Token
  • Source Code
Powered by GitBook
On this page

Was this helpful?

  1. Documents
  2. Any

Default

This method will set a default value that will be used when you pass null or undefined or even when you don't pass any value to the validate method

import Schema from "@rapidom/schema";

const Validator = Schema.number().default(0);

// All these cases will return 0
Validator.validate();
Validator.validate(null);
Validator.validate(undefined);

Once the default value is set, there's no use to make the validator required anymore

The default value must match all the validation rules as it's treated as a normal value

PreviousLabelNextRequired

Last updated 3 years ago

Was this helpful?