How can I validate "number of digits" from joi using nodejs?

Ravi Singh picture Ravi Singh · Sep 18, 2019 · Viewed 10k times · Source

i want that if the number of digits in the input field in less/more than 14(for example) then joi should return an error.

how can i do this with the type of number not for string.

Answer

waseem asgar picture waseem asgar · May 7, 2020

Validation for 10 digit numeric mobile number are given below

joi.string().length(10).pattern(/^[0-9]+$/).required(),

You should change the rule as per your requirement. pattern(your regex) is used to accept only digits, length() is used to validate how many character validation accepts and only work with string function.