Originally posted by James Sabre:
I don't think this can be done in one regex but it can be done in several ways with two
e.g.
boolean isGood = value.matches("\\d{5}") && !value.matches("([089])\\1{4}");
Having said I don't think this can be done I find it can!
boolean isGood = value.matches("[1-7]\\d{4}" +
"|0[1-9]\\d{3}|8[0-79]|9[0-8]\\d{3}" +
"|00[1-9]\\d{2}|88[0-79]\\d{2}|99[0-8]\\d{2}" +
"|000[1-9]\\d|888[0-79]\\d|999[0-8]\\d" +
"|0000[1-9]|8888[0-79]|9999[0-8]");
Not nice but it can be done!