Created
February 3, 2017 02:29
-
-
Save brownsoo/0383fdb241c77660c00f76cab8726971 to your computer and use it in GitHub Desktop.
Regular expression to check if the consecutive chars exist.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 문자열에 연속되는 문자가 있는지 확인 | |
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