Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK heres about 3 examples <a href="http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/" rel="nofollow">http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/</a></p> <p>I think the one you need is</p> <pre><code>package com.mkyong.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class EmailValidator{ private Pattern pattern; private Matcher matcher; private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@ [A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; public EmailValidator(){ pattern = Pattern.compile(EMAIL_PATTERN); } /** * Validate hex with regular expression * @param hex hex for validation * @return true valid hex, false invalid hex */ public boolean validate(final String hex){ matcher = pattern.matcher(hex); return matcher.matches(); } </code></pre> <p>}</p> <p>Whole combination is means, email address must start with “_A-Za-z0-9-” , optional follow by “.[_A-Za-z0-9-]“, and end with a “@” symbol. The email’s domain name must start with “A-Za-z0-9″, follow by first level Tld (.com, .net) “.[A-Za-z0-9]” and optional follow by a second level Tld (.com.au, .com.my) “\.[A-Za-z]{2,}”, where second level Tld must start with a dot “.” and length must equal or more than 2 characters.</p> <p>Example</p> <pre><code>package com.mkyong.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class EmailValidator{ private Pattern pattern; private Matcher matcher; private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@ [A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; public EmailValidator(){ pattern = Pattern.compile(EMAIL_PATTERN); } /** * Validate hex with regular expression * @param hex hex for validation * @return true valid hex, false invalid hex */ public boolean validate(final String hex){ matcher = pattern.matcher(hex); return matcher.matches(); } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload