Skip to content

Possible to validate extra requirements to optional field, in case a value is supplied? #503

Discussion options

You must be logged in to vote

Yes, this is possible but I would write it differently. Feel free to try it out in our playground.

import * as v from 'valibot';

const Schema = v.union([
  v.literal(''),
  v.string([v.length(5, 'Postal code must be 5 digits'), v.decimal()]),
]);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ollebergkvist
Comment options

Answer selected by ollebergkvist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants