I'm trying to solve a problem and i figure out that the best solution is to use regex.
I dont have advance knowledge on regex, so I really need your help.
The problem is that I need to identify if a string is phone number or a cell phone the way we use here in Brazil, like this:
The phone number could be in this format:
0 + XX + XXXXXXXX = 01121234567
Or
XX + XXXXXXXX = 1121234567
Or
XXXXXXXX = 21234567
In this case its a phone number, so it need to start with 2,3,4 or 5
And if its a cell phone it have 9 digits and must start with 9, exclusive, and second digit must be 6,7 or 8:
0 + XX + 9XXXXXXXX = 011961234567
Or
XX + 9XXXXXXXX = 11971234567
Or
9XXXXXXXX = 981234567
So, if i get the strings "011984160986", "11984160986" or "984160986", for example, I need to be able to identify that its a cell phone, and the same for phone numbers.
At the same time I must be able to check that string "84160289" its not a valid phone number.
Can anyone ligth me on this problem with a regex?
I not comfortable with use a lot of "ifs" in my code to validate this.
Thanks.