yup: 0 is not a positive number

.positive() accepts 0, but shouldn’t 0 not be considered a positive number?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 16 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@iPwnPancakes isn’t number().min(0) what you need ?

To be honest we just shipped with the issue, just hoping no one would do -0 @Sirrom84

So, zero is not positive, so, yes, this is a bug. The workaround (ugh!) yup.number().moreThan(0)

moreThan(-1) is this correct?

  payment: Yup.number()
      .required('Required')
      .moreThan(-1, 'Enter valid Amount')
      .typeError('Enter valid Amount'),

Issue with number().min(0) is that it still accepts -0 as valid value.

I have following PR #1295 to differentiate b/w -0 and 0

Which also indirectly makes 0 a positive number but does not change number.positive implementation

I know it’s closed and it will probably stay that way now, but to me, 0 is positive and negative. I even remember a weird math programming language calling x > 0 a non negative integer. Moreover, some languages define a +0 and a -0.

That said, I think there should be mention of that change somewhere in the changelog, because I almost broke my app by upgrading from 0.25 to 0.26 after looking at the changelog and I will certainly not be the only one…