I'm trying to make a javascript function with a regex, that will validate a phone number.
the rules are :
1. numbers only.
2. more then 10 numbers.
3. a dash ( - ) is allowed (optional).
first, I tried this one :
function validatePhone(phone) {
var phoneReg = /[0-9]{10,}/;
return (phoneReg.test(phone));
}
it worked well only on the first 2 rules, but not with the dash.
Then I tried var phoneReg = /[-0-9]{10,}/;
and even var phoneReg = [\d]+\-?[\d]+
but then the javascript was broken...
any thoughts ?