I'm trying to see if a string matches my country's phone number format, which is the area code (two digits that may or may not be preceded by a 0 and might also be between parenthesis) followed by 8 or 9 digits in which there may be an dash character before the 4 last digits. These are some valid formats:
'00 00000000'
'000-000000000'
'000 00000-0000'
'00 0000-0000'
'(00) 0000-0000'
'(000) 000000000'
So far this is the working expression I have:
p = /0?\d{2}\s?-?\s?\d{4,5}\s?-?\s?\d{4}/
I tried to use a conditional to see if the area code is inside parenthesis with /?(\() 0?\d{2}\)|0?\d{2} \s?-?\s?\d{4,5}\s?-?\s?\d{4}/
but got the (repl):1: target of repeat operator is not specified: /?(\() 0?\d{2}\)|0?\d{2} \s?-?\s?\d{4,5}\s?-?\s?\d{4}
error.
What am I doing wrong here?