I'm trying to develop a regex with the following rules:
- it should accept solely numbers,
- if the string contains any letters or any other special characters, the whole string should be rejected,
- regarding spaces, there should only be one consecutive number group, which can be surrounded by spaces,
- if there are more than one consecutive number group, with spaces in between the groups, that whole string should be rejected.
Example Cases:
- accepted:
- 1234
- [SPACE][SPACE]111[SPACE]
- [SPACE]111[SPACE][SPACE]
- declined:
- 1a234
- aa1234aa
- 1234a
- 12#4
- [SPACE]11[SPACE]111
- [SPACE]11[SPACE]111#
So far, I've come up with this ([0-9]+[^\s]*)
which can be seen here.
What modifications do I have to do to achieve the scenario I want above?