How to change error message "must be a `number` type..."
See original GitHub issueI try validate number field.
if I get value of type string or special symbols for example “++++” I get validation error “temperature must be a number
type, but the final value was: NaN
(cast from the value "++++"
).”
How can I to change this error message? if I use typeError(), I not get messages from check on matches and required.
I need check matches, reuqired, min and max for number field. What is best way?
// matches
if (!/^([0]([.][0-9]+)?|[1-9]([0-9]+)?([.][0-9]+)?)$/.test(temperature)) {
errors.temperature = 'Invalid format. Example 22, 22.1.';
}
// required
if (/^\s*$/.test(temperature)) {
errors.temperature = 'Please enter temperature. Value from 0 to 30.';
}
// min and max
Yup.object().shape({
temperature: Yup.number()
.min(0, 'Min value 0.')
.max(30, 'Max value 30.'),
})
Issue Analytics
- State:
- Created 5 years ago
- Reactions:18
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Yup.when: "`NaN` (cast from the value `NaN`)" - Stack Overflow
I get this error: "reserveVehicle must be a number type, but the final value was: NaN (cast from the value NaN ) ...
Read more >Custom validation message for input type="Number" when ...
Hi EveryOne, I am using an input with type set to number. In extended properties I have set the min attribute to "1"....
Read more >How should I formulate a validation error message for a ...
1 Answer 1 · Your first three (number is expected/required, value should be a number) are good. They call out that a number...
Read more ><input type="number"> - HTML: HyperText Markup Language
<input> elements of type number are used to let the user enter a number. They include built-in validation to reject non-numerical entries.
Read more >Custom Error Messages - express-validator
const { check } = require('express-validator'); app.post( '/user', // ...some other validations... check('password') .isLength({ min: 5 }) .withMessage('must be ...
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 FreeTop 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
Top GitHub Comments
schema.typeError('you must specify a number')