Comments (7)
Would you show me your usage code block ?
from libphonenumber-ios.
And, see below my sample test code.
// isViablePhoneNumber returns true for number that cannot be parsed #67
// https://rawgit.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/demo-compiled.html
NSString *countryCode = @"EN";
NSString *testNumber = @"927636539 nytt- (old)533021236";
BOOL isViableTestNumber = [phoneUtil isViablePhoneNumber:testNumber];
BOOL isValidTestNumber = [phoneUtil isViablePhoneNumber:testNumber];
NSLog(@"isValidTestNumber [%@]", isValidTestNumber ? @"YES":@"NO");
NSLog(@"isViableTestNumber [%@]", isViableTestNumber ? @"YES":@"NO");
NBPhoneNumber *parsedTestNumber = [phoneUtil parse:testNumber defaultRegion:countryCode error:&anError];
if (anError) {
NSLog(@"error : %@", anError.localizedDescription);
} else {
BOOL isValidNumber = [phoneUtil isValidNumberForRegion:parsedTestNumber regionCode:countryCode];
NSLog(@"isValidNumber [%@]", isValidNumber ? @"YES":@"NO");
NSError *parseError = nil;
NSLog(@"%@", [phoneUtil format:parsedTestNumber numberFormat:NBEPhoneNumberFormatE164 error:&parseError]);
}
from libphonenumber-ios.
I am using Swift. Here is the code I used for my test case, and it returns true
:
var phoneUtil: NBPhoneNumberUtil = NBPhoneNumberUtil.sharedInstance()
return phoneUtil.isViablePhoneNumber("927636539 nytt- (old)533021236")
I am using the latest source from GitHub. If I replace the number with, for example, "sdklfjdlksfj"
, it returns false
(as expected).
from libphonenumber-ios.
"isViablePhoneNumber" method only check "phone number" format in whole country.
You should check with your "countryCode" (ex "US", "CH")
NBPhoneNumber *parsedTestNumber = [phoneUtil parse:testNumber defaultRegion:countryCode error:&anError];
if (anError) {
NSLog(@"error : %@", anError.localizedDescription);
} else {
BOOL isValidNumber = [phoneUtil isValidNumberForRegion:parsedTestNumber regionCode:countryCode];
NSLog(@"isValidNumber [%@]", isValidNumber ? @"YES":@"NO");
NSError *parseError = nil;
NSLog(@"%@", [phoneUtil format:parsedTestNumber numberFormat:NBEPhoneNumberFormatE164 error:&parseError]);
}
from libphonenumber-ios.
But the problem is that if I run phoneUtil.parse(number, defaultRegion: isoCode, error: &error)
, with the country code, the function crashes with unexpectedly found nil while unwrapping an Optional value
. I can't check the status of the error object modified by the parse
function (the anError
variable in your example), because the app has already crashed by then.
I am perfectly fine with skipping those numbers that are in the wrong format, or those that can't be parsed, but in order to do that I need some way of knowing that before parse
crashes with unexpectedly found nil while unwrapping an Optional value
.
In any case, I think it's strange that "927636539 nytt- (old)533021236"
would be considered a viable phone number for any region. Or are there in fact regions where it is fine to have letters in the middle of the number?
from libphonenumber-ios.
OK, I see.
Please show me your code. I will check with swift.
from libphonenumber-ios.
#21
FYI
Still not solved ?
from libphonenumber-ios.
Related Issues (20)
- CocoaPods could not find compatible versions for pod "libPhoneNumber-iOS"
- I am getting "invalid number" error even If the number is valid
- Invalid Number Issue for Valid Number
- Phone number validation is not validating for Kuwait in iOS HOT 1
- how to handle errors
- The library doesn't support US number from new area code 572 in Oklahoma HOT 1
- Missing version tags HOT 1
- `isPossibleNumber(withReason...` returns incorrect case for local number
- Invalid Australian phone number HOT 2
- Dallas phone numbers don't work (945) HOT 1
- Xcode 14.3 Analyzer Warnings Related To Assumed Nullability HOT 1
- ERROR in XCode 14.3.1 libarclite_iphoneos.a clang: error: linker command failed with exit code 1
- ERROR in XCode 14.3.1 libarclite_iphoneos.a clang: error: linker command failed with exit code 1 HOT 1
- Missing spec for v1.1 in Cocoapods HOT 5
- In China, mobile numbers starting with "192" (for example: +86 19203868088) might not be recognized as valid phone numbers by standard phone number validation rules. This is because these numbers are often assigned to special services or virtual numbers, rather than regular mobile phone numbers.
- New version?
- iOS 16.6.1 breaking change - Invalid Country Code Error
- Privacy Manifest
- NBAsYouTypeFormatter format US number incorrectly
- Link unavailable
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 libphonenumber-ios.