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.

Parsing of swedish mobile phone numbers together with yup fail.

See original GitHub issue

Hi, I Im using the lib in a React app that Im building, and Im trying to use it together with yup. Im using it like this:

import * as Yup from 'yup';
import { parsePhoneNumber } from 'libphonenumber-js'

Yup.addMethod(Yup.string, 'phoneNumber', function () {
    return this.test({
      name: 'phoneNumber',
      exclusive: true,
      message: Not a valid number',
      test: (value) => {
        try {
          const phoneUtils = parsePhoneNumber(value, 'SE')
          const phoneNumber = phoneUtils
          return phoneUtils.isValidNumber(phoneNumber)
        } catch (e) {
          return false
        }
      }
    })
})

export default function ValidationSchema(values) {
    return Yup.object().shape({
        radioGroup: Yup.string().required("Du måste välja ett av valen."),
        phoneNumber: Yup.string().required('Du måste ange ett telefonnummer').phoneNumber()
    })
}

I verified it here https://libphonenumber.appspot.com/phonenumberparser?number=+467567891&country=SE And here https://libphonenumber.appspot.com/phonenumberparser?number=0734448472&country=SE and it works. Although when entering the phone number in my app I get the message saying that it is not a valid number, regardles the preceeding +46 or just 07? What am I missing?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
catamphetaminecommented, Nov 13, 2018

Provide an exact code sample

2reactions
catamphetaminecommented, Nov 13, 2018

Don’t post any “yup” references. Post a minimal and simple code sample which only uses libhphonenumber-js.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validate phone number with Yup? - Stack Overflow
Hi right now I'am solving same problem as you and I found possible solution. Validate phone number with string that matches Regex
Read more >
4 Ways to Call Private - wikiHow
1. Open your Phone app. If you wish to hide your phone number from one person while calling them, you can enter a...
Read more >
Log Operators Cheat Sheet | Sumo Logic Docs
The Search Operators cheat sheet provides a list of available Sumo Logic parsers, aggregators, search operators, and mathematical expressions with links to ...
Read more >
Input parser for functions - MATLAB - MathWorks
The parsing fails because the function receives arguments in the incorrect order and tries to assign name a value of 78 . This...
Read more >
Unknown error parsing query - but my colleague can run the ...
Hi all, I'm running some simple queries in Developer Console. My colleague can run these queries and get the information with no issues....
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