[Validation] required validate message is not appear with yup schema
See original GitHub issueDescribe the bug Required message is not appear with yup schema validation. only display ‘Invalid email’. I made yup schema what checks 2 validation, required and valid(w/ regex test)
To Reproduce Codesandbox: https://codesandbox.io/s/react-hook-form-required-not-appear-reproduce-losds
- submit form without fill the email field
- expect to display required message but invalid email is appeared.
- but native validate is works as what I expected
Expected behavior Display required error message
Screenshots

Desktop (please complete the following information):
- OS: MacOS 10.14.6
- Browser: Chrome
- Version: 76.0.3809.132
- Library: 3.23.12
Additional context
I think there is an issue in logic/validateWithSchema.ts. I’ve been through the same issue when I build a form without any form library just with yup. I have to find my old project to reference it. I need your opinion before that. do you think this is a bug? then, I’ll do.
Issue Analytics
- State:
- Created 4 years ago
- Comments:27 (15 by maintainers)
Top Results From Across the Web
Validation with Yup doesn't show the correct message
For a custom message to number type you should call the typeError() function: numberField: Yup.number().
Read more >Validation - Formik
Form-level validation is useful because you have complete access to all of your form's values and props whenever the function runs, so you...
Read more >Yup Email Validation: String Schema Code Examples
When you call schema.isValid on a Yup array field, it will only return true if all of the elements in the array are...
Read more >Yup - npm
Yup separates the parsing and validating functions into separate steps. cast() ... string.required(message?: string | function): Schema ...
Read more >Validation - VeeValidate
Form-level Validation. vee-validate supports using a validation schema to define all your validations on your fields beforehand so you don't have to define...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Don’t know if this is already discussed somewhere else, but if you found this issue while searching for this problem like I did, one possible solution is to use Yup.transform (with numbers) like this:
Here’s a working codesandbox forked from the @hitbear518 one https://codesandbox.io/s/react-hook-form-required-not-appear-reproduce-gitzy
In the OP’s case (RegExp.test for email), you could just skip the test if the value is
falsy:Codesandbox: https://codesandbox.io/s/react-hook-form-required-not-appear-reproduce-ycc4u
@bluebill1049 I noticed, thanks for the awesome work!
The order won’t help with required numbers though as the type (
Yup.number()) must be defined first? That’s not a problem of this library though and thetransformworkaround is just fine imo.