String should not contain a 9 digit number any where in the string. It can contain either a 8 digit or 10 digit or any number other than 9 digits.
Valid – 12345678, 1234567891, a 12345678
Invalid – 123456789, 123456789 a
Regex - "^(?!(^|.*\\D)\\d{9}(\\D|$)).*|^(?!(^|.*\\D)\\d{16}(\\D|$)).*";
Does not allow a 10 digit character
Try this: