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

Number validation fails with a valid number (".30") #1806

Closed
steve-deliverr opened this issue May 8, 2019 · 4 comments
Closed

Number validation fails with a valid number (".30") #1806

steve-deliverr opened this issue May 8, 2019 · 4 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@steve-deliverr
Copy link

Context

  • node version: 8.6.0
  • joi version: 15.0.2 (types/hapi__joi: 15.0.1)
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

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

I'm trying to validate a positive number, and I expect ".30" to be valid since isNan(".30") == false.

Joi.number().validate(".30")

Which result you had ?

error: ValidationError: "value" must be a number

What did you expect ?

error to be null

Please let me know if you need any additional information.

@WesTyler
Copy link
Contributor

WesTyler commented May 8, 2019

I'm not able to reproduce:

$ node -v
v8.6.0
Joi.number().validate('0.30');
/*
{ error: null,
  value: 0.3,
  then: [Function: then],
  catch: [Function: catch] }
*/
Joi.version
// '15.0.2'

@steve-deliverr
Copy link
Author

Thanks for the quick response, @WesTyler.

Joi.number().validate('0.30') works, but Joi.number().validate('.30') doesn't.

@WesTyler
Copy link
Contributor

WesTyler commented May 8, 2019

Oh geez, my bad. Sorry, didn't notice I habitually typed the leading 0

@WesTyler
Copy link
Contributor

WesTyler commented May 8, 2019

Looks like the leading decimal is messing with the regex before trying to convert here

@hueniverse hueniverse self-assigned this May 30, 2019
@hueniverse hueniverse added the bug Bug or defect label May 30, 2019
@hueniverse hueniverse added this to the 16.0.0 milestone May 30, 2019
@Marsup Marsup mentioned this issue Jun 9, 2019
@hueniverse hueniverse added the v16 label Aug 10, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

3 participants