Created
March 5, 2019 13:48
-
-
Save luck-alex13/bbdd622a98fe16ac23f0e53d3a8d054f to your computer and use it in GitHub Desktop.
Email and password validation helper
This file contains 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
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