regex - Email address verification and syntax reverification with java -


how perform email address validation? used following regular expression doesn't cover cases:

[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}

any appreciated.

you can try code snippet email syntax validation, full disclose, sample code take my company's email verification api.

/** valid email pattern. */ private static pattern validemail = null;  static {     /*      * want allow strange characters in emails?      * well, that's rfc2822 seems allow...      */     string atom = "[a-za-z0-9!#$%&'*+-/=?^_`{|}~]";     string domain = "(?:[a-za-z0-9](?:[-a-za-z0-9]*[a-za-z0-9]+)?)";      validemail = pattern.compile("(^" + atom + "+" + "(?:\\." + atom + ")*)" + "@((?:" + domain + "{1,63}\\.)+"             + domain + "{2,63})$", pattern.case_insensitive); } 

...

    try {         matcher matcher = validemail.matcher(emailaddress);         if (!matcher.matches()) {             result.setvalidformat("invalid format");             return result;         }         result.setvalidformat("ok");          string user = matcher.group(1);         string hostname = matcher.group(2);      ....           } catch (exception e) {         throw new emailverifyexception(e);     }     return result; 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -