title: Email validation in C++
body: <p>Okay so I'm trying to make a program which allows user to input their email. Their email will be considered valid if two stipulations are met: A. there must be an "@" sign somewhere in there and B. there must be a period after the "@". I got the code down for the most part, but I am having some difficulty when it comes to validating emails that have a period before the "@" sign. If they have the period before the "@" sign they are considered valid, but they shouldn't be. For example, entering <code>text.example@randomcom</code> is considered valid.</p>
  
  <p>Can anyone help me figure out what I did wrong? Thank you in advance!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cctype&gt;
  #include &lt;cstring&gt;
  using namespace std;
  
  int main()
  {
      int x = 25; //random size enough to hold contents of array plus one for               null terminator
      char input[x]; //array to hold input
      int sizeOf; //holds length of input array
      char* ptr = nullptr; //pointer
      char* ptr2 = nullptr; //pointer
  
      cout &lt;&lt; "Enter your email address\n";
      cin.getline(input,x);
      sizeOf = strlen(input);
  
      for(int i = 0; i &lt; sizeOf; i++)
      {
          ptr= strstr(input, "@"); //searches input array for "@" string
          if(ptr != nullptr) 
          {
              break;
          }
      }
  
      for(int i = 0; i &lt; sizeOf; i++)
      {
          ptr2 = strstr(input, "."); //searches input array for "." string
          if(ptr2 != nullptr &amp;&amp; &amp;ptr2 &gt; &amp;ptr)
          {
              break;
          }
      }
  
      if(ptr != nullptr) //validates input of "@" sign
      {
          if(ptr2 != 0 &amp;&amp; &amp;ptr2 &lt; &amp;ptr) 
              {
                  cout &lt;&lt; "Email accepted.\n";
              }
  
          else
              {
                  cout &lt;&lt; "Missing . symbol after @\n";
              }
      }
  
      else
      {
          cout &lt;&lt; "Missing @ symbol\n";
      }
  
  
  
  return 0;
  }
  </code></pre>