admin管理员组

文章数量:1384778

How can I modify my validation schema such that the entered value is boolean, either 1 or 0? not true false etc

  formValue: Yup.number()
        .boolean()
        .typeError('boo'),

How can I modify my validation schema such that the entered value is boolean, either 1 or 0? not true false etc

  formValue: Yup.number()
        .boolean()
        .typeError('boo'),
Share Improve this question asked Jun 29, 2021 at 9:52 x89x89 3,50015 gold badges79 silver badges163 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

You can use the test method .

formValue: Yup.number().test('is boolean',
  'Please enter either 1 or 0',
  (value) => value === 0 || value === 1)

Yup - test

本文标签: javascriptyup schema for boolean values (0 or 1)Stack Overflow