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-
I have to agree that validating phone numbers is a difficult task. As for this specific problem i would change the regex from
/^(()?\d{3}())?(-|\s)?\d{3}(-|\s)\d{4}$/
to
/^(()?\d{3}())?(-|\s)?\d{3}(-|\s)?\d{4}$/
as the only one more element that becomes unnecessary is the last dash/space.