Giter VIP home page Giter VIP logo

Comments (7)

iziz avatar iziz commented on August 19, 2024

Would you show me your usage code block ?

from libphonenumber-ios.

iziz avatar iziz commented on August 19, 2024

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.

larsekman avatar larsekman commented on August 19, 2024

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.

iziz avatar iziz commented on August 19, 2024

"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.

larsekman avatar larsekman commented on August 19, 2024

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.

iziz avatar iziz commented on August 19, 2024

OK, I see.
Please show me your code. I will check with swift.

from libphonenumber-ios.

iziz avatar iziz commented on August 19, 2024

#21
FYI

Still not solved ?

from libphonenumber-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.