^(?=.{8,10}$)\d+(?:[ _]\d+)*$
Explanation:
^ # Start of string
(?=.{8,10}$) # Assert length 8-10
\d+ # One or more digits
(?: # followed by
[ _] # one space or underscore
\d+ # one or more digits
)* # zero or more times.
$ # End of string
2
solved PHP regular expression for given condition [duplicate]