datafaker
datafaker copied to clipboard
Normalized phone_number
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] At my job I often use phone_number feature, but I work with phone numbers without any signs (only country code and digits). I have to normalize phone numbers by myself.
Describe the solution you'd like
A clear and concise description of what you want to happen.
It would be perfect to add new method normalizedPhoneNumber() to PhoneNumber class which returns normalized phone.
Of cource I can implement it by myself
Completely agree. I was looking at a similar related issue myself, or seems that at the moment it's very inconsistent if the international or local format is used. So I was thinking of keeping the current phone number method, but adding two extra methods, one for international and one for nationally formatted numbers.
We could make these numbers both normalized, as to address both issues at once. Would that work for you?
@bodiam yes, sounds good. I’ll research implementation ways at the end of the week
what do you think about normalizedPhoneNumber(Set<Character> characters2keep)
where a user could pass characters with those the user is ok and normalizedPhoneNumber() which removes everything except digits?
e.g. for a phone number (01837) 73 427
normalizedPhoneNumber() returns 0183773427
normalizedPhoneNumber(" ".chars().mapToObj(e -> (char) e).collect(Collectors.toSet())) returns 01837 73 427
normalizedPhoneNumber("()".chars().mapToObj(e -> (char) e).collect(Collectors.toSet())) returns (01837)73427
I'm fine with that, I'm mostly interested in having local numbers and international, like:
020584944 vs +9920584944
I think this issue is not a real priority at the moment, so I'm going to close it. Happy to have international and normalized phone numbers if someone is keen picking it up though.
@bodiam I could take up this task. But, first, I wanted to know in a few words how it should look like. For example, in the .yml files add lists for international and local numbers, and have, for example, two methods phoneNumberInternational and phoneNumberLocal
Well, when looking at this:
https://libphonenumber.appspot.com/phonenumberparser?number=%2B61403475700
I thought it might be nice to have something like a national and international format. So yes, two lists or regexes would probably be the way forward, though the buildup of phone numbers is slightly more complex. I'm not really sure yet what it should look like, but if you want to give it a shot, feel free, and happy to help.