Reputation: 113
I need a regex for allowing only numbers + following characters (+
, ,
(
,)
)
I have done this :
^-{0,1}\d+$
But this is taking only numbers ..how we can write it for the charecters as well?
Upvotes: 1
Views: 109
Reputation: 92976
What you need is a character class. You can define one with square brackets []
. Then just add all those characters, ranges or predefined shorthand classes to your character class.
[-+\d() ]
Such a character class will then match exactly one character out of the class members.
You may want to read more details about character classes on regular-expressions.info or a real brief overview about basic regex features on my blog post "What absolutely every Programmer should know about regular expressions"
Upvotes: 0