Schema - Max (Date)
The .max
method is used to validate whether a given date does not exceed a specified maximum date. It ensures that the input value is less than or equal to the maximum allowed date, making it useful for scenarios like setting the latest allowable birthdate, deadlines, or event dates.
This method is particularly useful for validating dates where you need to enforce an upper bound, such as ensuring a date is not later than a certain reference date.
Example: Date Validation with .max
Below is an example of how to use .max
to validate whether a date is less than or equal to a reference date:
import { schema } from "vkrun"
const exampleSchema = schema().date().max(new Date(2020, 4, 5)) // May 5, 2020
const validateA = exampleSchema.validate(new Date(2020, 4, 5)) // true
const validateB = exampleSchema.validate(new Date(2020, 4, 6)) // false
console.log(validateA) // true
console.log(validateB) // false