Skip to content

Instantly share code, notes, and snippets.

@luck-alex13
Created March 5, 2019 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luck-alex13/bbdd622a98fe16ac23f0e53d3a8d054f to your computer and use it in GitHub Desktop.
Save luck-alex13/bbdd622a98fe16ac23f0e53d3a8d054f to your computer and use it in GitHub Desktop.
Email and password validation helper
package com.example.user.testapphandh;
import android.util.Patterns;
import java.util.regex.Pattern;
public class ValidationHelper {
/*
( # Start of group
(?=.*\d) # must contains one digit from 0-9
(?=.*[a-z]) # must contains one lowercase characters
(?=.*[A-Z]) # must contains one uppercase characters
(?=.*[@#$%]) # must contains one special symbols in the list "@#$%"
. # match anything with previous condition checking
{6,20} # length at least 6 characters and maximum of 20
) # End of group
*/
private static final String PASSWORD_PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})";
public static boolean isValidEmail(String email) {
if (email == null) return false;
Pattern pattern = Patterns.EMAIL_ADDRESS;
return pattern.matcher(email).matches();
}
public static boolean isValidPassword(String password) {
if (password == null) return false;
Pattern pattern = Pattern.compile(PASSWORD_PATTERN);
return pattern.matcher(password).matches();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment