Regex pattern throws ANR on Android -
i developing android application email validation, using regex, attached below:
it works in conditions, conditions, gives me app not responding
errors.
for example, if put text specific length, no @
, gives me anr. if email length below range gives me proper validation error. regex looks like:
public static final string email_pattern ="(?:[a-za-z0-9!#$%&'*+-/=?^_`{|}~.]*)+(\\w[a-za-z0-9!#$%&'*+-/=?^_`{|}~.]+)@(?:[a-za-z0-9-.]*)"; // here gives proper validation error fgefjkbgjerk.com gives anr 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 problem regex or implementation?
i believe should use pattern this:
public static final pattern email_pattern = pattern.compile("^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,6}$", pattern.case_insensitive);
and if you're not sure matcher, use pattern:
public static boolean checkemailvalidations(string email) { matcher matcher = email_pattern .matcher(email); return matcher.find(); }
Comments
Post a Comment