if (password1.length() >= 15){
final String PasswordPattern = "^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])[0-9A-Za-z]{15,}$";
Pattern pattern = Pattern.compile(PasswordPattern);
Matcher matcher = pattern.matcher(password1);
if(matcher.matches() == true){
if (password1.equals(password2)){
SavePreferences(password1.toString());
//Intent intent = new Intent(LockAppActivity.this, ScreenLockActivity.class);
Intent intent = new Intent(LockAppActivity.this, PhoneNumActivity.class);
startActivity(intent);
}
else{
pass1.setText("");
pass2.setText("");
Toast.makeText(LockAppActivity.this,"Both passwords are not equal!",Toast.LENGTH_SHORT).show();
}
}
I want user to enter password with at least 15 characters which must consists of Capital and Small letters, numbers and symbols. But I only know how to create pattern with Capital and Small letters and numbers… How can I include all the symbols in the pattern… Kindly check on my pattern code part… thanks
You could add the section
(?=.*(\W|_))to check for anything except alphanumeric (A-Z, a-z, 0-9) symbols. Or, you could specify a set of symbol characters like(?=.*[\.\*]). If you do, replace the contents of the[]with all the characters you want to allow, using a backslash before each character that has a regex function. (The example shows a section that allows two characters,.and*.)Then you’ll need top update the section that counts the number of occurrences. Since we’re dealing with all characters now, we can replace the
[0-9A-Za-z]with., leaving us with:^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*(\W|_)).{15,}$. Replace the single\with two\\since you’re placing this in a Java string.Remember that Android keypads can vary, so not all of them are guaranteed to have the same symbols.