Skip to content

Instantly share code, notes, and snippets.

@digvijaybhakuni
Created July 6, 2014 08:17
Show Gist options
  • Save digvijaybhakuni/4a76283513683aed6212 to your computer and use it in GitHub Desktop.
Save digvijaybhakuni/4a76283513683aed6212 to your computer and use it in GitHub Desktop.
Validate password with regular expression
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Give true is all condition matches, otherwise false.
* @param String
* @return boolean
*/
private boolean validatePassword(String password){
Pattern pattern = Pattern.compile("((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})");
Matcher matcher = pattern.matcher(password);
return matcher.matches();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment