Regular Expression for Password Field In Android

January 04, 2018 , 0 Comments

Rule :
The password must be at least 8 characters long and include a number, lowercase letter, uppercase letter and special character (e.g. @, &, #, ?)

Use this Pattern:


How it works? :

^ # start-of-string
(?=.*[0-9]) # a digit must occur at least once
(?=.*[a-z]) # a lower case letter must occur at least once
(?=.*[A-Z]) # an upper case letter must occur at least once
(?=.*[@#$%^&+=]) # a special character must occur at least once replace with your special characters
(?=\\S+$) # no whitespace allowed in the entire string
.{8,} # anything, at least six places though
$ # end-of-string

How its Use? :

public boolean isValidPassword(final String password) {

Pattern pattern;
Matcher matcher;

final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{4,}$";

pattern = Pattern.compile(PASSWORD_PATTERN);
matcher = pattern.matcher(password);

return matcher.matches();



Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google



Best Watch Store

Popular Posts

Contact Form


Email *

Message *