I want that the text field only accept numeric values and spaces. What is regular expression for this? I was trying with \d+$
Thanks
Yes, also your regex will match if there are just spaces. My reply was to Neha choudary's comment. @Pierre Three years later -- I came across this question today, saw your comment; I use regex hero (regexhero.net) for testing regular expressions.
$ means "Match the end of the string" (the position after the last character in the string).
In regex, the uppercase metacharacter is always the inverse of the lowercase counterpart. \d (digit) matches any single digit (same as [0-9] ). The uppercase counterpart \D (non-digit) matches any single character that is not a digit (same as [^0-9] ).
\W means "non-word characters", the inverse of \w , so it will match spaces as well.
This one should work :
[0-9 ]+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With