Acceptable input : any 9 digit number
Not acceptable : 123456789
and 987654321
I am using [0-9]{9}
but I want extra condition as well
Acceptable input : any 9 digit number
Not acceptable : 123456789
and 987654321
I am using [0-9]{9}
but I want extra condition as well
I would suggest that, as you only have two exceptions, you write the regex to confirm it's a 9-digit numeric number, and then special case the two edge cases you mention. Not as technically challenging, but much easier to read the code.
Try:
^(?!123456789|987654321)\d{9}$
^
- beginning of string
(?!123456789|987654321)
- don't continue matching if 123456789
or 987654321
is found
\d{9}
- match 9 digits
$
- end of string