Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error at integer validation #1544

Closed
ManuSenpai opened this issue Jul 17, 2018 · 3 comments
Closed

Error at integer validation #1544

ManuSenpai opened this issue Jul 17, 2018 · 3 comments
Assignees
Labels
breaking changes Change that can breaking existing code bug Bug or defect
Milestone

Comments

@ManuSenpai
Copy link

Context

  • node version: 8.6.0
  • joi version: 13.2.0
  • environment (node, browser): Chrome
  • used with (hapi, standalone, ...): Standalone

What are you trying to achieve or the steps to reproduce ?

I'm trying to validate a possitive integer which length is between 10 and 15 characters

This is the code I am using

function validateNumber (value) {
return _.isNull(joi.validate(value, joi.string().required().min(10).max(15)).error) &&
_.isNull(joi.validate(value, joi.number().integer().min(0).required()).error);
}

Which result you had ?

I used as a value 999999999. (9 integers and a decimal point) and joi validates it as a 10 digit integer

What did you expect ?

I expected it to throw an error as it is not a digit. Given 999999999.9 as value throws an error correctly.

@WesTyler
Copy link
Contributor

I'm pretty sure this is because of how Node.js handles decimal points:

> Number.isSafeInteger(1.)
true
> Number.isSafeInteger(1.0)
true
> Number.isSafeInteger(1.1)
false

@Marsup Marsup added this to the 14.0.0 milestone Aug 9, 2018
@Marsup Marsup self-assigned this Aug 9, 2018
@Marsup Marsup added bug Bug or defect breaking changes Change that can breaking existing code labels Aug 9, 2018
@Marsup
Copy link
Collaborator

Marsup commented Aug 9, 2018

Will be fixed in 14. Closing for now.

@lock
Copy link

lock bot commented Jan 9, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking changes Change that can breaking existing code bug Bug or defect
Projects
None yet
Development

No branches or pull requests

3 participants