I'm doing some form validation for a phone number. I only need to find out that it is only numbers or spaces in the phone field. The below checks only for [0-9], which I used in another function, but when I try to reverse it to /\D/.test(phoneChk) (which apparently is the reverse of d) it doesn't seem to work anymore? I am new to javascript, and definitely new to RegEx so am trying to find a simple way to do this. I know there is plenty of examples on the stackoverflow of RegEx, but none seem to be working within the if statement (at least that I can work out).
function fnCheckPhone(strName) {
strName.style.background = "#FFFFFF";
var phoneChk = strName.value;
if (phoneChk == "" || /\d/.test(phoneChk)) {
strName.style.background = "#FBEC5D";
return false
}
else {return true}
Any help would be appreciated....