首页 > 解决方案 > Yup validation decimal number

问题描述

Thank you in advance, I'm using yup in my React project to validate my schema, problem is in field called "price":

price: Yup.number().required("Required"),

when I add value with comma like 45,89 yup throw me an error that price must be a number. I'm like that float with comma is same like float with dot. Is there a way to take current value from validation schema and replace it? like current.replace(",",".")?

标签: javascriptvalidationyup

解决方案


you can use typeError(message: string): Schema to define an error message for failed type checks. The ${value} and ${type} interpolation can be used in the message argument.


推荐阅读