-
Notifications
You must be signed in to change notification settings - Fork 216
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
Lack of phone number extension support is a deal breaker. #129
Comments
Why not store the extension as a separate field in the database and then output the formatted number + "ext. XXXX". |
You could probably also wrap your calls to libphonenumber-js and cut "x1234" or "ext1234" off the end of your inputs/data values before calling it. That way you could store it in the database however you want and/or allow whatever input format you want. |
We store the extension in a separate column in the database, but part of what I like about libphonenumber is the "as you type" feature and the ability to extract the extension. I'm assuming, since you dropped extension support, that this feature also doesn't support them. |
@jpickwell I am not familiar with the Android/Java libphonenumber. I searched briefly but I couldn't find any support for this feature. Are you saying that this ability exists in the Java version of the library and you want it in the JavaScript version as well? With regards to my own advice, I was just saying that it seems like you can do this yourself pretty easily by intercepting calls to const libphonenumberJs = require("libphonenumber-js")
const asYouType = libphonenumberJs.asYouType;
// Raw input from your onChange event...
var rawInput = '5554443333#1234';
// '#' could be any string, i.e. 'ext', 'x' or you could split on multiple tokens...
var parts = rawInput.split('#');
var phonePart = parts[0];
var phoneFormatted = new asYouType('US').input(phonePart);
var phoneExtension = parts[1].trim();
console.log('Phone: ' + phoneFormatted); // "Phone: (555) 444-3333"
console.log('__Ext: ' + phoneExtension); // "__Ext: 1234"
'OK'; Run it with RunKit |
@waynebloss, google-libphonenumber has this (and it's a 1:1 with Google's own JS library). https://ruimarinho.github.io/google-libphonenumber/#google-libphonenumber-methods-i18nphonenumbersphonenumber |
@jpickwell Ahhh ok, thank you. It seems like the author of this library ( So, someone would probably have to fork this project to do it. |
Most likely no one ever will. Here's a link to Google's demo illustrating phone number extensions parsing: The phone number parsing code is in this file: The regular expression for parsing extensions:
libphonenumber-js/source/parse.js Lines 78 to 87 in 5c72aff
And the original Google's library has it: As you type is implemented in this file: |
Ok, fuck you, if it's really that simple then I'll try it. |
@catamphetamine Thanks for your code and for doing the extra work to find out how to make this change (and possibly implementing it)! It would be nice to easily capture the extension without having a separate input. |
Well, I got it parsed and formatted. |
I am not using this library yet, but I was hoping to. Perhaps @jpickwell will answer. |
So original Google's library only supports extensions when parsing and formatting, and not when using "as you type" formatter. |
I made an assumption that the "as you type" formatter handled extensions. |
just a note, for anyone who wants to do phone extensions for AsYouType, you can do something like this:
|
While phone number extensions (eg ext1234 or x1234) may not make sense when working with ordinary consumers, websites that deal with business or enterprise customers require this functionality. There's a large developer base out there that works only with B2B and B2E development that need to support extensions.
The text was updated successfully, but these errors were encountered: