Skip to content

Instantly share code, notes, and snippets.

@brownsoo
Created February 3, 2017 02:29
Show Gist options
  • Save brownsoo/0383fdb241c77660c00f76cab8726971 to your computer and use it in GitHub Desktop.
Save brownsoo/0383fdb241c77660c00f76cab8726971 to your computer and use it in GitHub Desktop.
Regular expression to check if the consecutive chars exist.
// 문자열에 연속되는 문자가 있는지 확인
public static boolean checkConsecutiveChars(@NonNull String password, int consecutiveLength) {
if (password.length() < consecutiveLength) {
return false;
}
for (int i = 0; i <= password.length() - consecutiveLength; i++) {
char s1 = password.charAt(i);
char s2 = password.charAt(i + 1);
char s3 = password.charAt(i + 2);
if (Math.abs(s1 - s2) == 1 && s1 - s2 == s2 - s3) {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment