📦
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

Validate

Validate any value by using this method which exists on all Schema types

import Schema, { SchemaError } from "@rapidom/schema";

Schema.number().validate(1); // returns 1

try {
  Schema.number().validate("not number"); // fails
} catch (error) {
  if (error instanceof SchemaError) {
    // validation error
  }
  
  // not validation error
}
PreviousPipeNextArray

Last updated 3 years ago

Was this helpful?