You could use a regular expression:
Matcher m = Pattern.compile("[A-Z][A-Z]([A-Z]|\\d)\\d\\d").matcher(bilnumer);
if (m.find()) {
System.out.println(bilnumer + " is a valid number plate");
} else {
System.out.println(bilnumer + " is not a valid number plate");
}
Extract from wikipedia: '...a regular expression (abbreviated regex or regexp) is a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings'. So here: [A-Z][A-Z]([A-Z]|\\d)\\d\\d
I have made an expression that consists of two capital letters, a capital letter or a number followed by two numbers.
Breaking the expression down further:
[A-Z]
means any character in the range from A to Z (so capitals)
\\d
means a digit.
|
is the or operator in java