Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to find the country of a given full phone number? #12

Closed
finferflu opened this issue Jun 26, 2017 · 4 comments
Closed

Is it possible to find the country of a given full phone number? #12

finferflu opened this issue Jun 26, 2017 · 4 comments

Comments

@finferflu
Copy link

For example:

PhoneNumber.getCountry('+441618811234')

Output:

UK

Having to specify the country when initialising a phone number can be counter-productive when you don't know where the number is from.

Thanks!

@finferflu finferflu changed the title Is it possible to find a country given a full phone number? Is it possible to find the country of a given full phone number? Jun 26, 2017
@grantila
Copy link
Owner

If the number you provide is prefixed +, awesome-phonenumber will try to detect the country automatically.

const PhoneNumber = require( "awesome-phonenumber" );

const pn = new PhoneNumber( '+441618811234' );
const cc = pn.getRegionCode( ); // "GB"

or shortcut:

const cc = PhoneNumber( '+441618811234' ).getRegionCode( );

@finferflu
Copy link
Author

Thanks for the very quick answer, very much appreciated. I think the documentation should make this a bit clearer, as I thought I couldn't initialise the PhoneNumber object without specifying the country. Given such possibility, this module becomes 100% more useful to me. Thanks again!

@grantila
Copy link
Owner

Noted and fixed, thanks for the feedback!

@finferflu
Copy link
Author

You're welcome, and thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants