Remove the outer square brackets:
if(name.matches("[K][H][1-9][0-9]?")){
Watch the IDEONE demo
The problem is that you included the entire pattern in the character class with an external [...] , and all the characters inside (except the brackets) were treated as single literals, and the whole expression could correspond to only 1 character.
Speaking of optimization: rotation is not required here, since you can apply ? quantifier to class [0-9] to make it optional. ? matches 0 or 1 occurrence of the previous subpattern.
Also note that [K][H] makes sense if you plan to add additional parameters to character classes, otherwise you could use
if(name.matches("KH[1-9][0-9]?")){
or
if(name.matches("KH[1-9]\\d?")){
\d is an abbreviated class that matches a digit.
source share