I am new to regex and I am burning hours just to get it right. I need to allow these patterns
NPA-XXX-XXXX
(NPA) XXX-XXXX
NPAXXXXXXX
where NPA = numbers 0 to 9 and X is also any number 0 to 9
so this is valid
123-456-7890
1234567890
(123) 456-7890
but not this
(123)-456-7890 // because there is a dash after closing parenthesis
(123)456-7890 // because there is no space after closing parenthesis
QWE-456-7890 // because there are one or more alpha characters
I use this
Regex r = new Regex(@"^?\(?\d{3}?\)??-??\(?\d{3}?\)??_??\(?\d{4}?\)??-?$");
from System.Text.RegularExpressions
What would be the regular expression that would match the valid?