title: java code for regex of email validation
body: <p>I tried to simulate email validation without regular expression in java and wrote this code. I need help to improve efficiency of this code (or give me a better way to solve this issue please) </p>
  
  <p>regular expression: <code>^[(a-zA-Z-0-9-\\_\\+\\.)]+@[(a-z-A-z)]+\\.[(a-zA-z)]{2,3}$</code></p>
  
  <pre><code>public static boolean isValidEmailAddress(String email) {
  
      boolean flag1 = false;
      boolean flag2=false;
      boolean flag3=false;
      int j=0;
      char[] emailChars = email.toCharArray();
      for (int i = 0; i &lt; emailChars.length;) {
          char c = emailChars[i];
          if (Character.isLetterOrDigit(c)) {
                  i++;
              if(flag1==true&amp;&amp;flag2==true){
                  j++;
              }
          } else if (c == '@' &amp;&amp; flag1==false&amp;&amp;flag2==false &amp;&amp; flag3==false) {
              i++;
              flag1=true;
          } else if(c=='.' &amp;&amp; flag1==true &amp;&amp; flag2==false&amp;&amp;flag3==false){
              i++;
              flag2 = true;
          }
          if(j==2 || j==3){
              flag3=true;
          }
      }
      return flag1&amp;&amp;flag2&amp;&amp;flag3;
  
  }
  </code></pre>