Reputation: 7577
I want to allow only the following characters in a string: digits, parentheses and the plus sign, which is [0-9] ( ) +
I can't seem to get a combination to get the validator to return true, the only option seems to be an list of every other possible character that's NOT allowed... which would make for a large list!
Am I missing something?
Upvotes: 0
Views: 367
Reputation: 53553
You need to slash-escape parens and the plus, because they have special meanings in regex:
/^[\d\(\)\+]+$/
Upvotes: 1
Reputation: 141839
This should work:
/^[0-9()+]*$/
The regex I gave you there also accepts the empty string. If you want to disallow empty then change the *
near the end to a +
.
Upvotes: 1