Alex
Alex
ZZod
Created by Alex on 2/7/2024 in #questions
Alex - Hi there, I am trying to validate a numb...
Thanks again, very helpfull!
23 replies
ZZod
Created by Alex on 2/7/2024 in #questions
Alex - Hi there, I am trying to validate a numb...
z
.string()
.regex(/^[-]?\d*\.?\d+$/, "Must be a number")
.pipe(z.coerce.number().int("Must be an integer").positive("Must be a positive number"))
.safeParse(maxQuantity);
z
.string()
.regex(/^[-]?\d*\.?\d+$/, "Must be a number")
.pipe(z.coerce.number().int("Must be an integer").positive("Must be a positive number"))
.safeParse(maxQuantity);
23 replies
ZZod
Created by Alex on 2/7/2024 in #questions
Alex - Hi there, I am trying to validate a numb...
yes, true, thanks!
23 replies
ZZod
Created by Alex on 2/7/2024 in #questions
Alex - Hi there, I am trying to validate a numb...
now using this, which works as I originally intended:
z
.string()
.regex(/^\d*\.?\d+$/, "Must be a number")
.pipe(z.coerce.number().int("Must be an integer").positive("Must be a positive number"))
.safeParse(maxQuantity);
z
.string()
.regex(/^\d*\.?\d+$/, "Must be a number")
.pipe(z.coerce.number().int("Must be an integer").positive("Must be a positive number"))
.safeParse(maxQuantity);
23 replies
ZZod
Created by Alex on 2/7/2024 in #questions
Alex - Hi there, I am trying to validate a numb...
yes, works, thanks
23 replies
ZZod
Created by Alex on 2/7/2024 in #questions
Alex - Hi there, I am trying to validate a numb...
nope, but still cannot access the code sandbox
23 replies
ZZod
Created by Alex on 2/7/2024 in #questions
Alex - Hi there, I am trying to validate a numb...
maybe I am just reading one error for some reason, i will check
23 replies
ZZod
Created by Alex on 2/7/2024 in #questions
Alex - Hi there, I am trying to validate a numb...
I am also very confused, I will investigate further, just wanted to check I am not doing something obvious wrong
23 replies
ZZod
Created by Alex on 2/7/2024 in #questions
Alex - Hi there, I am trying to validate a numb...
correct, so how is the int check passing?
23 replies
ZZod
Created by Alex on 2/7/2024 in #questions
Alex - Hi there, I am trying to validate a numb...
cannot open the sandbox. what is that regex doing exactly? because I would expect my inital schema to give me an error because coerce should fail. also, because I get "Must be a positive number" as error, that means the int check was passed, which again means, coerce returned a number. that should not be the case, because coerce just uses the Number() constructor, which would give NaN when passing "d"
23 replies