【问题标题】:Yup allow more than 0 decimal value是的,允许超过 0 个十进制值
【发布时间】:2021-10-14 02:30:56
【问题描述】:

我想允许大于 0 的数字带有十进制数

我试过了

const schema = yup.object().shape({
  amount: yup.number().min(0),
});

但是,它允许我不想要的 0 值。所以,我尝试了

const schema = yup.object().shape({
    amount: yup.number().min(0.1),
});

但是,它不允许 0.001 或 0.0002

如何更改允许多于 0 的十进制值。任何帮助将不胜感激。

【问题讨论】:

  • 您是否尝试过使用正则表达式?

标签: reactjs validation yup


【解决方案1】:

您可以使用yup.number.positive() 代替min(0)

https://github.com/jquense/yup#numberpositivemessage-string--function-schema

【讨论】:

  • 但是,它允许0值
  • 哦,你可以试试yup.number.moreThan(0)
  • 我使用的是 0.21.3
  • 请更新到最新版本0.32.9
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-27
  • 1970-01-01
  • 1970-01-01
  • 2022-11-29
  • 2012-09-05
  • 2018-05-29
  • 1970-01-01
相关资源
最近更新 更多