Is it possible to format phone numbers in contact similar to how numbers are formatted from system settings?
I.E. we could enter 123456789 as contact’s phone, and it would format to (123) 456-789. A few options could be selectable from system settings, in the same section as date and number format.
I’m happy to help as our team has been asking for this - but I’m not sure how the Frappe team would want this enhancement to be done.
So I have done the above by being able to set options to Phone and then strip characters and re-format.
For US phone numbers it’s rather easy - either 10 or 11 digits, and really only a few ways to format them. When involving the international formats, it gets quite complicated…
"""
Phone number format.
INTERNATIONAL and NATIONAL formats are consistent with the definition in
ITU-T Recommendation E123. For example, the number of the Google
Switzerland office will be written as "+41 44 668 1800" in INTERNATIONAL
format, and as "044 668 1800" in NATIONAL format. E164 format is as per
INTERNATIONAL format but with no formatting applied, e.g. "+41446681800".
RFC3966 is as per INTERNATIONAL format, but with all spaces and other
separating symbols replaced with a hyphen, and with any phone number
extension appended with ";ext=". It also will have a prefix of "tel:"
added, e.g. "tel:+41-44-668-1800".
Note: If you are considering storing the number in a neutral format, you
are highly advised to use the PhoneNumber class.
"""
So far, this is my best lead. I guess it would work well as a first effort if you agree?
Also, I have set the event to occur on insert & save, after the db update & before post-save-methods. I didn’t know a way to read from the field before it was saved in the db - if there is a way to do that, it may be better.
Let me know your thoughts & I’ll send a PR once I’ve made changes & tested.
You will have to check if there is any field with Phone formatting and then fix this.
Or better, just make a general purpose wrapper method and let the developer call this the validate method of the controller to fix / validate phone numbers/
Hey there. Bringing this thread back to life. I’m not sure if there’s a way to format phone numbers in your contacts to match your system settings, but there might be some apps or third-party software that could help with that. It’s worth looking into if it’s a big issue for you. Also, have you considered using a disposable phone number? It can be a great way to protect your privacy and avoid spam calls. There are a bunch of services out there that offer disposable phone numbers, so it might be worth checking out.