People, how do I create a regular expression, in which it should accept numbers with DDD, and should I also accept non-DDD numbers?
People, how do I create a regular expression, in which it should accept numbers with DDD, and should I also accept non-DDD numbers?
Regex reg = new Regex(@"(\([0-9]{2}\)|)[0-9]{4,5}-[0-9]{4}");
reg.isMatch("(12)12345-1234"); //retorna true
reg.isMatch("(12)1234-1234"); //retorna true
reg.isMatch("12345-1234"); //retorna true
reg.isMatch("1234-1234"); //retorna true
reg.isMatch("123-1234"); //e qualquer outra combinação retorna false