I found this code in some website, and it works perfectly. It validates that the phone number is in one of these formats: (123) 456-7890 or 123-
If you are looking for 10 and only 10 digits, ignore everything but the digits-
return value.match(/\d/g).length===10;