This is my suggested solution:
/^(?=.*\d)[\d ]+$/.test(val)
(?=.*\d) states that there is at least one digit at the input. Otherwise, the input with spaces may match.
Please note that this does not place any limit on the number of digits (just to make sure that they are at least 1 digit) or where space should appear at the input.
source share