嘿嘿伙计们!
我有一些街道字段,通常应该包括门牌号码,所以我想检查该字段是否包含字符和数字(0-9)。如果两者都正确,则输入正确。顺便说一句,我不想使用正则表达式。当有人可以帮助我时,会很棒。我不知道如何检查它。
谢谢。
我用用户输入试过这个,我测试了铁路 10
System.out.println("Street:");
strasse = input.readLine();
while(true) {
while (strasse.length() > 35) {
System.out.println("Input has a limit of 35 signs. Enter again:");
}
for (int i = 0; i < strasse.length(); i++) {
if (Character.isDigit(strasse.charAt(i))) {
checkDigit = true;
}
else if (Character.isLetter(strasse.charAt(i))) {
checkLetter = true;
}
if (checkDigit && checkLetter == true) {
break;
}
else { // <= PROBLEM. You should give a chance to test all chars from address
System.out.println("Must contain at least 1 number or character. Enter again:");
strasse = input.readLine();
}
}
}
它没有为 checkDigit 提供真正的回报。