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 apply regexp for validate number? How to change message for required?

See original GitHub issue

I’m trying to validate a number field.

    Yup.object().shape({
        temperature: Yup.number()
                        .min(0, 'Minimal value 0')
                        .max(30, 'Maximum value 30') 
                        .matches(/^([0]([.][0-9]+)?|[1-9]([0-9]+)?([.][0-9]+)?)$/, {
                            message:'Inccorect format. Example 25 or 25.1',
                            excludeEmptyString: true
                        })
                        .required('Temperature is required. Please enter value from 0 till 30')
    })

I got error if apply matches for number,

and I can not to change message for required. I got default message.

  1. How apply regexp for validate number?
  2. How to change message for required?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
arthurysongcommented, Jan 20, 2021

This is how I tested for number and for regex; I used mixed and wrote custom tests.

const schema = yup.object().shape({
  price: yup
    .mixed()
    .required('Price is required')
    .test('type', "Price must be a number", value => !isNaN(value))
    .test('validDollar', "Price must be a valid dollar amount", value => /^\d*.?\d{0,2}$/.test(value)),

4reactions
Martinnordcommented, Aug 2, 2018

@zhrvdns Would you mind showing how you accomplished this? And thanks @jquense for this awesome validation tool.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change validation message only for Regex pattern ...
and following com it is giving regex message as "Please match the requested format"..How can we change this message to a meaningful one.But...
Read more >
Examples of javascript form validation using regular expressions
In this tutorial you will see how to use regular expressions to validate. Through a list of examples , we will build a...
Read more >
Form Input Validation Using Only HTML5 and Regex - Code
Let's say you want to make sure that usernames are only alphanumeric. This can be done easily with the help of the pattern...
Read more >
Restricting Text Responses With Regular Expressions
To use a regex in KoboToolbox, follow these steps¶ · Prepare a Text question type. · Go to the question's Settings. · Go...
Read more >
Form Validation In JavaScript Using Regular Expression
This video on Validation in JavaScript will let you know everything about how a user's data can be validated with the help of...
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