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(),
});
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(),
});
Share
Improve this question
edited Oct 4, 2022 at 16:47
Talha Jutt
563 silver badges13 bronze badges
asked Nov 21, 2021 at 18:40
ClancinioClancinio
9427 gold badges27 silver badges45 bronze badges
2
-
3
You need to drop
positive()
in order for it work. – Hassan Imam Commented Nov 21, 2021 at 18:57 - Ahhhhhh thank you very much :) – Clancinio Commented Nov 21, 2021 at 19:10
2 Answers
Reset to default 1You may add number.min(1, '')
& number.max(1,'')
.
To specify the minimum and maximum quantity also
<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('Обязательное поле'),