date
Creates a date schema.
const Schema = v.date<TMessage>(message);
Generics
TMessageextends ErrorMessage<DateIssue> | undefined
Parameters
messageTMessage
Explanation
With date you can validate the data type of the input. If the input is not a date, you can use message to customize the error message.
Returns
SchemaDateSchema<TMessage>
Examples
The following examples show how date can be used.
Force minimum
Schema that forces a minimum date of today.
const MinDateSchema = v.pipe(v.date(), v.toMinValue(new Date()));
Validate range
Schema that validates a date in a range.
const DateRangeSchema = v.pipe(
v.date(),
v.minValue(new Date(2019, 0, 1)),
v.maxValue(new Date(2020, 0, 1))
);
Related
The following APIs can be combined with date.
Schemas
array, exactOptional, intersect, lazy, looseObject, looseTuple, map, nonNullable, nonNullish, nonOptional, nullable, nullish, object, objectWithRest, optional, record, set, strictObject, strictTuple, tuple, tupleWithRest, undefinedable, union
Methods
assert, config, fallback, getDefault, getDefaults, getFallback, getFallbacks, is, message, parse, parser, pipe, safeParse, safeParser
Actions
check, brand, description, flavor, gtValue, guard, ltValue, maxValue, metadata, minValue, notValue, notValues, rawCheck, rawTransform, readonly, title, toMaxValue, toMinValue, transform, value, values
Utils
entriesFromList, isOfKind, isOfType
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/date/