I have the following regex
^(?!0{8})
@Pattern
You have made some mistakes in your regex. Checking if a string contains only 8 zeros. (According to your question, that is what you want to avoid) can be done with the regex "^(0{8})$"
. This regex will return true if there are 8 zeroes in a row, and that is the only content in the string. ^
matches the beginning and
$
matches the end.
You can use java to negate the result.
String s = "123456789";
System.out.println(!s.matches("^(0{8})$"));