I am developing Android application with email validation, for which I am using Regex, which is attached below:
It works in certain conditions, but for certain conditions, it gives me App Not Responding
errors.
For example, if I put some text with some specific length, but no @
, then it gives me ANR. If my email length is below that range it gives me proper validation error. My regex looks like:
public static final String EMAIL_PATTERN ="(?:[A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]*)+(\\w[A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+)@(?:[A-Za-z0-9-.]*)";
// Here it gives proper validation error for fgefjkbgjerk.com but gives ANR
for
sjkfghhrghergfhfgfghkfgkfgkjkgergejkgrjekfghfghfg.com
public static boolean checkEmailValidations(String regex,String email){
boolean patternStatus=false;
Pattern pattern= Pattern.compile(regex);
Matcher matcher = pattern.matcher(email);
if( matcher.matches()){
patternStatus=false;
}else{
patternStatus=true;
}
return patternStatus;
}
Is there a problem with the Regex or my implementation?