0

Should match the following:-

  • (222)-333-4444
  • (010)-123-3435
  • (100)-454-6565

But Should disallow:-

(000)-000-0000

The only problem is when the input is entered all zeros. Otherwise my regex:-

^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$

works fine__.

Demo http://regexstorm.net/tester

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
karthi
  • 41
  • 9
  • what is the language you're using? – Amit Joki Dec 22 '14 at 11:30
  • @HamZa There is no regex to support the correctly marked answer unfortunately, although there has been a great insight in building a comprehensive regex and various other solutions given. – karthi Dec 22 '14 at 15:27

1 Answers1

1

You can use this negative lookahead based regex:

^(?![0()-]+$)\(?(\d{3})\)?[-. ]?(\d{3})[-. ]?(\d{4})$

RegEx Demo

  • (?![0()-]+$) is a negative lookahead that says fail the match if matches only [0()-] character till the end.
anubhava
  • 761,203
  • 64
  • 569
  • 643