I am developing an Ionic app, and I need to validate an input field that may accept either a phone number, an email or a username. However, my application should be prepared to accept phone numbers from all over the world, which means that I should have a sort of generic solution to guarantee I am sending a valid number to a server.
I was checking how Facebook accept different phone formats to log in and I would like to make something similar. So I was wondering how I could achieve such thing. It allows me to log in using three different formats:
0 (11) 9 1234-5678
when typing011912345678
(11) 9 1234-5678
when typing11912345678
55 (11) 9 1234-5678
when typing5511912345678
But as I am in Brazil, I believe it is easier to control it using a RegEx to validate only brazilian format numbers. But, how could I validate different phone numbers when I don't know where the user is? I'd like to hear from you guys if someone has achieved a solution for such problem. Thanks!
Edit: The main problem here is not using a RegEx to validate an international phone number format itself, but, how can I guarantee that even though the user may not type his International Country Code I still allow him to log in if he uses only his central office codes plus his subscriber number?