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

How to get Significant number with Mask #116

Closed
IvanNavin opened this issue Feb 14, 2024 · 1 comment
Closed

How to get Significant number with Mask #116

IvanNavin opened this issue Feb 14, 2024 · 1 comment

Comments

@IvanNavin
Copy link

I am working on a design that includes a select dropdown for country codes. I obtain the codes using the following approach:

const codes = getSupportedCallingCodes()
  .map((code) => `+${code}`)
  .sort((a, b) => a.localeCompare(b));

Subsequently, I receive a phone number, for example: "+380987654321". I pass this number to parsePhoneNumber:
const pn = parsePhoneNumber(value);
Then, I propagate the necessary values into the code select and the input field:

if (pn.countryCode) {
  setCode(`+${pn.countryCode}`);
}
if (pn.number?.significant) {
  setInputValue(pn.number.significant);
}

My objective is to have the country code in the select as "+380" and the remaining part of the number in the input, where I am utilizing significant.

Question: Do you have a ready solution or recommendations on how to implement the significant part with a mask?

@grantila
Copy link
Owner

If you have a valid phonenumber, you can filter by the countryCode field, which is the 380 in your example.

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