question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to change error message "must be a `number` type..."

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:18
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

325reactions
jquensecommented, Nov 21, 2018

schema.typeError('you must specify a number')

321reactions
fadeomarcommented, Feb 2, 2021
numberFiled: Yup.number()
                        .typeError('you must specify a number')
                        .min(0, 'Min value 0.')
                        .max(30, 'Max value 30.')
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found