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

Open
IvanNavin opened this issue Feb 14, 2024 · 0 comments
Open

How to get Significant number with Mask #116

IvanNavin opened this issue Feb 14, 2024 · 0 comments

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?

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

1 participant