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 - |
Pregunta
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?
Solución 2
Otros consejos
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.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow