Reputation: 942
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
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
Reputation: 172
You may add number.min(1, '')
& number.max(1,'')
.
To specify the minimum and maximum quantity also
Upvotes: 1