Is it possible to use zod to validate a comma-separated string #1869
-
Hey there, I'm trying to validate some queryparams coming through to an endpoint, i.e. |
Beta Was this translation helpful? Give feedback.
Answered by
JacobWeisenburger
Jan 12, 2023
Replies: 2 comments 5 replies
-
what should the value of
|
Beta Was this translation helpful? Give feedback.
3 replies
-
Is this what you are looking for? const schema = z.object( {
foo: z.string()
.transform( value => value.split( ',' ).map( Number ) )
.pipe( z.number().array() ),
} )
console.log( schema.parse( { foo: '1,2,3,4' } ) )
// { foo: [ 1, 2, 3, 4 ] } |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
grug
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this what you are looking for?