I'd check if \D+
returns a match. If so, there's at least one element that isn't a digit.
Also, Test if string is a number in Ruby on Rails gives some answers without using regular expressions.
Regex to check the data entered into the field contains only numbers
-
28-06-2022 - |
Question
I'm using a field with string datatype, I want add validation to that field which will check if the string entered into the field contains only numbers, please help me with the regex?
Solution 2
OTHER TIPS
You can use the below given pattern for checking:
^(0|[1-9][0-9]*)$
If it returns true, it means that there are only digits inside the field, otherwise not.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow