利用Pattern和Matcher:
public static void main(String[] args) {
private static final Pattern REPEATABLE_CHARACTERS = Pattern.compile("^[0-9]*$");
Matcher matcherNew = REPEATABLE_CHARACTERS.matcher("123456");
Matcher matcherNewAgain = REPEATABLE_CHARACTERS.matcher("newAgainPassword12");
boolean resultNew = matcherNew.matches();
boolean resultNewAgain =matcherNewAgain.matches();
System.out.println(resultNew);
System.out.println(resultNewAgain);
}