Q:

Regular Expression for Phone Number

I need a Javascript RegEx through which I can validate phone number. RegEx should handle following criteria 

It should only consist of numbers ( ) + and -
Count of + should not exceed 1
Count of - should not exceed 4
There must be only one pair of ()
If '(' is present in phone number then ')' must be present.

Thanks for the help!
Hussain.

A:

Try this:
function valid_phone_number(ph) {
  var regex = /^(?!([^-]*-){5})(\+\d+)?\s*(\(\d+\))?[- \d]+$/gi;
  return regex.test(ph);
}

I'm new to regular expressions, so please be nice. :-)

