Skip to content

Temporary coerce #455

Discussion options

You must be logged in to vote

Something like that could work. Check it out in our playground.

const Schema = v.union(
  [v.string([v.regex(/^-?\d+(?:\.\d+)?$/)]), v.number()],
  [
    v.custom((input) => Number(input) >= 0, 'Number is too small'),
    v.custom((input) => Number(input) <= 100, 'Number is too big'),
  ]
);

Replies: 1 comment 1 reply

Comment options

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

Answer selected by fabian-hiller
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