Parsing of swedish mobile phone numbers together with yup fail.
See original GitHub issueHi, 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:
- Created 5 years ago
- Comments:14 (8 by maintainers)
Top 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 >
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
Provide an exact code sample
Don’t post any “yup” references. Post a minimal and simple code sample which only uses
libhphonenumber-js
.