If we want to put in some validation and reformatting for phone numbers to make sure they conform to N. Am. standard for 10 digit numbers, is there a simple way to catch this for everywhere a phone number is entered or edited (including edit in place), rather than having to search and deal with each form separately?
There's an extension that does precisely this: https://github.com/cividesk/com.cividesk.normalize
It used to be in the extensions directory, but it's gone now for some reason. It uses libphonenumber, and it formats international numbers appropriately based upon the country in the address.
FYI Civi already does one pass at normalization behind the scenes - whenever a phone number is entered or updated, a numeric-only version of it (stripped of all punctuation and spaces) is stored in the
phone_numeric field in the database. This is the field that is used for search.
It doesn't enforce a certain number of digits, but thought you'd want to know that this calculated field exists.
Rather than trying to solve it at the form level, you could use
hook_civicrm_post() to look for a 'Phone' object. From there, doing a phone number reformat by talking to libphonenumber is pretty straightforward. I've built a little Node app that exposes it as a service; if that helps I could chuck it onto GitHub. There is also a PHP port of that library.
I realize it's not ideal as we are cleaning up after the data comes in rather than bringing it in pristine, but it's a smaller dev effort for something workable.