queria testar, sem ter q fazer um if com 9 ORs, preciso saber c a string inicia com 8 números iguais as possibilidades são 9
//Ps.: Começar com "00000000" é permitido
if (str.startsWith("11111111",0) ||
str.startsWith("22222222",0) ||
str.startsWith("33333333",0) ||
str.startsWith("44444444",0) ||
str.startsWith("55555555",0) ||
str.startsWith("66666666",0) ||
str.startsWith("77777777",0) ||
str.startsWith("88888888",0) ||
str.startsWith("99999999",0)) {
//....
}
queria fazer com regex e checar, mas não sei bem como fazer, se alguem puder me ajudar
…
pronto resolvido
[code]//remove todos os caracters não numericos
srt= srt.replaceAll( “\D*”, “” );
//expressão regular para os 8 primeiros digitos.
Pattern firstEightDigitsEquals = Pattern.compile(srt.charAt(0)+"{8}.");
if (firstEightDigitsEquals.matcher(srt).find()) {
//…
}[/code]