Gundam Meister
Gundam Meister

Reputation: 1495

Regular Expression to match only numbers, (, ), + and -

What is the correct regular expression to match only number, parentheses, plus and minus signs?

I've spent a long time on http://rubular.com/ and I came up with this for matching numbers only:

/\A[^a-zA-Z]*\z/

How can I do this so that it also matches for parentheses, plus and minus signs?

Upvotes: 1

Views: 74

Answers (1)

anubhava
anubhava

Reputation: 785196

You can use this regex:

/^[\d()+-]+$/

Upvotes: 2

Related Questions