Clancinio
Clancinio

Reputation: 942

Why is number().min() not working in Yup validation?

Here is my Yup schema. The validation on asset works fine, but I'm not sure why it is not working on the amount?

  const validationSchema = Yup.object().shape({
      asset: Yup.string().required("Required!"),
      amount: Yup.number()
        .required()
        .min(5, "Must be more than 5")
        .positive(),
    });

Upvotes: 1

Views: 17867

Answers (2)

Jack Pts
Jack Pts

Reputation: 179

<Typography color="error.main">
   { errors?.bonus_add }
</Typography>

...

 bonus_add: yup.number()
    .test('numbers', 'Допустимы только цифры', value => !value || /^[0-9]+$/.test(value))
    .test('lessThanTen', 'Поле “Количество бонусов” должно содержать не более 9 символов', value => !value || value.toString().length < 10)
    .required('Обязательное поле'),

Upvotes: 0

Douglas Fernandes
Douglas Fernandes

Reputation: 172

You may add number.min(1, '') & number.max(1,''). To specify the minimum and maximum quantity also

Upvotes: 1

Related Questions