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…
I looked into https://github.com/daviddrysdale/python-phonenumbers (python port of Google’s libphonenumber library) but there isn’t a lot in terms of formatting - either spaces or dashes. See here:
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.