-2

I have a regular expression to check phone number.It returns 'true' for 10 zeroes. How to change regular expression to return 'false' for 10 zeroes. Following is my code

var phoneno = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;

phoneno.test('8129587912');// returns true .Works good

phoneno.test('asdff');// returns false .Works good

phoneno.test('0000000000');//returns true. Not Working As Expected

Please help to solve this issue.

Rahul K R
  • 191
  • 4
  • 20

2 Answers2

0

This is what you asked for:

var phoneno = /^(?!0000000000)\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
Robert McKee
  • 21,305
  • 1
  • 43
  • 57
0

If just want exclude 10 zeros circumstance, you can make a special case for that:

if( !/0{10}/.test(phonenum) ){
    //another rules...
}
Nic
  • 1
  • 2