Joi: contact number length validation not working with integer

Created on 3 Oct 2018  路  3Comments  路  Source: sideway/joi

i'm trying to validate contact number in nodeJS using joi.
i seen many solution like using converting number to string we can do.
but i want to do this using only integer.

 const schema = {
        mo: Joi.number().length == 10,
}

thanks for your help.

support

Most helpful comment

You'd want something like Joi.number().integer().min(1000000000).max(9999999999). This is assuming you want mo to be an integer with a "length" of 10.

All 3 comments

You'd want something like Joi.number().integer().min(1000000000).max(9999999999). This is assuming you want mo to be an integer with a "length" of 10.

I'm not even sure I understand the question, next time try to use examples. So it's either what @arb suggested or Joi.string().length(10).

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

Was this page helpful?
0 / 5 - 0 ratings