Use ^(. *[^0-9]|)(1000|[1-9]\\d{0,2})([^0-9]. *|)$ which will match 1000 or a non-zero digit followed by up to two further digits. It will also allow other characters on either end of the number.