Your regex allows for or a space or hyphen between any pair of digits, is that a requirement? Assuming it is, here's what I would use:
^\d(?!(?:[-\s]?\d){7,8}$)(?:[-\s]?\d){6,25}$
I think the biggest problem with your regex is the placement of the lookaheads. They have to be used at the beginning of the regex to do any good. What's happening in your regex is that the \d(?:[-\s]?\d){6,}
consumes all the digits it can, then the lookaheads are applied at the end of the string, where there are no more characters of any kind. So, being negative lookaheads, they always succeed.
Another problem is the dot (.
) following each lookahead; because they're not inside the lookaheads, and the enclosing groups are not optional, each dot has to consume one character, which is not accounted for by any of the range quantifiers (especially the last one, {9,26}
), and is not limited to matching just a digit, hyphen or space.
It looks like you're trying to use the captive lookahead idiom (as I call it) demonstrated in this answer. It's not useful in this case.