Last active
August 29, 2015 14:20
-
-
Save JonghyuKim/68ed5733a3c34d95fd9e to your computer and use it in GitHub Desktop.
[Android]Regex Password Number + Char + Special
This file contains hidden or 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 int checkPassword(String password){ | |
String charRegex = "a-zA-Z"; | |
String numRegex = "0-9"; | |
String specialRegex = "\\~`!@#\\$%\\^&\\*\\(\\)\\-+\\|\\{\\}\\[\\];\\\\:'\"<>\\?,./_="; | |
//Number Only, Char Only, Special Only | |
if(Pattern.matches(String.format("^[%s]*$",charRegex), password) || | |
Pattern.matches(String.format("^[%s]*$",numRegex), password) || | |
Pattern.matches(String.format("^[%s]*$",specialRegex), password)){ | |
return -1; | |
} | |
//Number + Char + Special | |
//Number + Char | |
if(Pattern.matches(String.format("^[%s%s%s]*$", charRegex,numRegex,specialRegex), password)){ | |
//Number + Special, Char + Special remove | |
if(Pattern.matches(String.format("^[%s%s]*$", charRegex,specialRegex), password)|| | |
Pattern.matches(String.format("^[%s%s]*$", numRegex,specialRegex), password)){ | |
return -2; | |
} | |
return 0; | |
} | |
//Number + Char + Not suport special char | |
if(Pattern.matches(String.format("^(?=.*\\d)(?=.*[a-zA-Z])(?=.*[^%s]).*$",specialRegex), password)){ | |
return -3; | |
}; | |
//other... | |
return -4; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment