Hello,
Do the standard formatting for phone number is not sufficient for your needs (based on country of address if I remember well) ?
If not, using javascript to reformat user entries does not seem the best way to go.
I'd rather try one of the following methods of the view you are using : DO_VALIDATE_INPUT or DO_FINISH_INPUT.
Best regards,
Sylvain AGUETTAZ