jquense / yup

Dead simple Object schema validation
MIT License
22.94k stars 935 forks source link

how to specify number of digits in yup for a number() #2213

Closed vishal-gits closed 6 months ago

vishal-gits commented 6 months ago

Is there a method available in yup to limit the number of integers in the input box.

phone: yup.number().max(10), This actually specifies the number amount , how can I specify the number of digits .

What could be a solution to restrict for an input field of phone, so that it is a number of 9 digits.

jquense commented 6 months ago

What could be a solution to restrict for an input field of phone,

Generally use a string phone numbers aren't really numbers. you will run into trouble if you try and save a phone number into e.g. an int column

vishal-gits commented 6 months ago

yes, you are right, i viewed other codes doing the same, and for strictly restricting to digits as strings, i can couple it with regex. also since phone numbers have different formats with respect to different countries, so cannot be generalized and keep it custom.