acoutts / flutter_libphonenumber

Leverages libphonenumber to allow for asynchronous and synchronous formatting of phone numbers in Flutter apps. Includes a TextInputFormatter to allow real-time AsYouType formatting.
MIT License
59 stars 72 forks source link

isValidPhoneNumber true for invalid numbers. #36

Closed JoshanTandukar closed 1 year ago

JoshanTandukar commented 1 year ago

+9779861eeeeee this number seems sure invalid. However, if passed to , await PhoneNumberUtil.isValidPhoneNumber( phoneNumber: phone, isoCode: selectedCountryCode.code!, );

    is return true because the length exactly matches. Thank you for the package though.
martipello commented 1 year ago

isValidPhoneNumber is from the lib phone number package i can't see that its in this flutter_libphonenumber package please let me know if i'm wrong because I'd appreciate it being moved into this package so we can migrate fully from that to this

acoutts commented 1 year ago

@martipello you can do the same by calling parse and if you get a null result then it's not a valid number, if it is valid it would return the country info associated with it.

martipello commented 1 year ago

@martipello you can do the same by calling parse and if you get a null result then it's not a valid number, if it is valid it would return the country info associated with it.

Very cool I will do just that, many thanks

martipello commented 1 year ago

@acoutts it cant return null do you mean if it throws? or do we mean getFormattedParseResult? in fact it kind of looks like getFormattedParseResult calls parse and if it throws returns null, so just use getFormattedParseResult and check if its null

acoutts commented 1 year ago

sorry you're right, but that's correct. just check the error when you pass a bad number to it and catch that accordingly.