Comments (9)
After doing some more exploration, theres some connection to the number of digits and parsing of the extension value:
(lldb) po PhoneNumber(rawNumber: "7035205555 x555")
▿ PhoneNumber
- countryCode : 1
- leadingZero : false
- nationalNumber : 7035205555
▿ numberExtension : Optional("555")
- Some : "555"
- rawNumber : "7035205555 x555"
(lldb) po PhoneNumber(rawNumber: "7035205555 x5555")
▿ PhoneNumber
- countryCode : 1
- leadingZero : false
- nationalNumber : 7035205555
▿ numberExtension : Optional("5555")
- Some : "5555"
- rawNumber : "7035205555 x5555"
(lldb) po PhoneNumber(rawNumber: "7035205555 x55")
▿ PhoneNumber
- countryCode : 1
- leadingZero : false
- nationalNumber : 7035205555
- numberExtension : nil
- rawNumber : "7035205555 x55"
(lldb) po PhoneNumber(rawNumber: "7035205555 x5")
▿ PhoneNumber
- countryCode : 1
- leadingZero : false
- nationalNumber : 7035205555
- numberExtension : nil
- rawNumber : "7035205555 x5"
from phonenumberkit.
I've forked the library and dug in a bit, and this problem is actually caused by NSDataDetector
in RegularExpressions.swift in the phoneDataDetectorMatches
method.
This code snippet highlights the issue. Drop into a play ground to see it in action.
import Foundation
let dataDetector = try! NSDataDetector(types: NSTextCheckingType.PhoneNumber.rawValue)
var nsString = "7035551234 x42" as NSString
var stringRange = NSMakeRange(0, nsString.length)
var matches = dataDetector.matchesInString("7035551234 x42", options: [], range: stringRange)
matches.forEach { (result) -> () in
print(result.phoneNumber) // prints "Optional("7035551234")"
}
nsString = "7035551234 x422" as NSString
stringRange = NSMakeRange(0, nsString.length)
matches = dataDetector.matchesInString("7035551234 x422", options: [], range: stringRange)
matches.forEach { (result) -> () in
print(result.phoneNumber) // prints "Optional("7035551234;422")"
}
I guess the question is, long term, whether PhoneNumberKit should rely on the iOS data detectors.
from phonenumberkit.
Thanks a lot for looking into this @pzearfoss, very interesting bug...
The NSDataDetector was added for efficiency as part of the effort to boost parsing speeds. If it fails there is a fallback to libPhoneNumber's original Regular Expression. The problem here is that it doesn't technically fail but doesn't produce the expected result either.
I will have a solution for this soon...
from phonenumberkit.
Thanks @marmelroy, this is great news.
We can work around it in the meantime. Do you think this represents a bug with NSDataDetector? It seems like it to me, but it's so obvious that I can't believe it would be missed. I think I might file a radar for it.
from phonenumberkit.
Any updates on this?
from phonenumberkit.
Not yet. It definitely seems like a bug in NSDataDetector but I need to properly benchmark the benefit of using it vs the custom regular expression before deciding on the next move.
from phonenumberkit.
@marmelroy Thanks for the update!
from phonenumberkit.
Quick update to say that this is still an issue...
from phonenumberkit.
Fixed (finally) by b71cbad
from phonenumberkit.
Related Issues (20)
- Formatter.swift adding an extra 0 for Bangladesh numbers HOT 2
- Privacy manifest HOT 2
- Unable to parse czech numbers from string HOT 2
- Vietnamese landline ranges cannot be parsed/invalid. HOT 1
- Adding the +90 561 area code to the metadata for Turkish operator Turkcell. HOT 1
- Not able to validate Phone Number for non-US region on 3.7.9 / 3.7/10 HOT 2
- Adding the +60 11 area code to the metadata for Malaysia operator U Mobile.
- onPhoneNumberChangeHandler after entering 10digits we are getting value as nil for specific numbers only
- onPhoneNumberChangeHandler after entering 10digits we are getting value as nil for specific numbers only. can please look at it.... HOT 1
- onPhoneNumberChangeHandler after entering 10digits we are getting value as nil for specific numbers only HOT 3
- onPhoneNumberChangeHandler after entering 10digits we are getting value as nil for specific numbers only
- Unable to parse the mobile number with the Indian region code HOT 1
- From iOS 17 am facing delay in formating phone number HOT 1
- While building Xcode Playgrounds I get an Error: Undefined symbols for architecture x86_64: "___isPlatformVersionAtLeast" HOT 1
- Missing support for textContentType autocomplete with example placeholder + prefix enabled HOT 1
- Build failed because PhoneNumberKit.swiftmodule is not built for arm64
- Cannot find type 'PhoneNumberTextField' in scope & SPM wrong version
- It's impossible to identify Mexican numbers with (1) HOT 3
- Please review Austria phone number sample for ios HOT 1
- Setter for 'defaultRegion' is deprecated!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phonenumberkit.