0

Currently I have an expression:

numMatches = phone.match(/[^\d\s\-]/gi);

if (numMatches != null) {
    alert(invPhnNo);
}   

This gives an alert if any characters other than digit, space and hyphen are entered. But still accepts if only hyphen and spaces are given without a single digit. Now i would want it to alert if atleast a digit is not there. So a digit is mandatory. Can have zero or more spaces and hyphen and no other characters.

Can anyone suggest an approach to this?

Kara
  • 6,115
  • 16
  • 50
  • 57
Shirin
  • 1

1 Answers1

1

You could either use the standard regexp refered to by Trever, but you could also simply run another .match(/\d+/g) on the string and if both succeed, you can be sure that it complies with your requirements and also has at least one digit.

zatatatata
  • 4,761
  • 1
  • 20
  • 41