title: Using a regular expression with posix syntax to validate an email address
body: <p>Here is the validation that we have to use for email validation.</p>
  
  <p>Using posix syntax:</p>
  
  <pre><code>^[[:graph:]]\\+@[[:graph:]]\\+\\.[[:graph:]]\\+$
  </code></pre>
  
  <p>I have written sample program to validate, but i have failed to give right Email address to fulfill posix syntax regular expression. Could you please any one help me out to correct my below Java example.</p>
  
  <h2>Java Example:</h2>
  
  <pre><code>import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  
  
  public class RegexMatches {
  
      public static void main(String args[]) {
  
        String email = "sudheer@gmail.com";
        String pattern ="^[[:graph:]]\\+@[[:graph:]]\\+\\.[[:graph:]]\\+$";
        //String pattern = ".+@.+\\.[a-z]+";// This is Working fine.
  
        if (!testRegex(email, pattern))
          System.out.println("Validator Exception");
        else
          System.out.println("Success");
      }
  
       public static boolean testRegex(String value, String regex) {
         Pattern pattern = Pattern.compile(regex);
         Matcher matcher = pattern.matcher(value);
         return matcher.matches();
      }
  }
  </code></pre>