Created
March 26, 2018 16:53
-
-
Save hatamiarash7/8db302e94053a2ede7754ce2147737f4 to your computer and use it in GitHub Desktop.
Android Validation rules
This file contains hidden or 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
public static boolean isValidEmail(String target) { | |
boolean check1 = Patterns.EMAIL_ADDRESS.matcher(target).matches(); | |
Pattern pattern; | |
Matcher matcher; | |
String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; | |
pattern = Pattern.compile(EMAIL_PATTERN); | |
matcher = pattern.matcher(target); | |
boolean check2 = matcher.matches(); | |
return target.isEmpty() || check1 && check2; | |
} | |
public static boolean isValidPhone(String target) { | |
return target.startsWith("09") && target.trim().length() == 11 && target.matches("[0-9]+"); | |
} | |
public static boolean isValidPassword(String target) { | |
return target.length() >= 8 && ASCII.isASCII(target) && target.matches("\\A\\p{ASCII}*\\z"); | |
} | |
public static boolean isValidName(String target) { | |
return Pattern.compile("^(?=.*[a-zA-Z가-힣])[a-zA-Z가-힣]{1,}$").matcher(target).matches(); | |
} | |
public static boolean isValidNickName(String target) { | |
return Pattern.compile("^(?=.*[a-zA-Z\\d])[a-zA-Z0-9가-힣]{2,12}$|^[가-힣]$").matcher(target).matches(); | |
} | |
public static boolean isNumber(String target) { | |
return Pattern.compile("^(-?0|-?[1-9]\\d*)(\\.\\d+)?(E\\d+)?$").matcher(target).matches(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment