I assume "eventually" means (in English) "optionally". (I know languages where this form occurs, though I gotta say they don't match your name.) Also that "figures" means "group of digits", not "(individual) digits".
[21-27] does not mean
"any two-digit number in the set 21 22 23 24 25 26 27"
It means
"any one-digit number in the set 2 1-2 7-- i.e. 1 2 7"
Similarly
([ ]?[0-9]{2}){2}
does not mean "four numerals, optionally preceded by a space".
It means "two numerals, optionally preceded by a space, and then the identical group again".
It is safer to get rid of the spaces beforehand. Either design your input to ignore them (one way is to have three separate boxes, each of which skips to the next box as soon as the user has entered the right number of digits), or strip them out before you run any code.
I make it
22(2[1-7]|30)[0-9]{4}
or
22(2[1-7]|30)\d{4} (if your setup supports the \d notation)
although \d\d\d\d may be just as fast. If you need to capture, put the
whole thing in parentheses as (for example)
(22(2[1-7]|30)[0-9]{4})
[edited by: lucy24 at 7:05 pm (utc) on Oct 19, 2011]