title: Validate string for invalid characters
body: <p>I was doing some research today of how to validate a string input for invalid characters such as digits, unfortunately with no success. I am trying to validate string for getting customer's name, and check if there are any digits.</p>
  
  <pre><code>#include "stdafx.h"                                             
  #include &lt;string&gt;               
  #include &lt;iostream&gt;
  #include &lt;conio.h&gt;
  #include &lt;algorithm&gt;
  #include &lt;cctype&gt;
  
  using namespace std;
  
  string validateName(string name[], int i)
  {
      while(find_if(name[i].begin(), name[i].end(), std::isdigit) != name[i].end()){   
          cout &lt;&lt; "No digits are allowed in name." &lt;&lt; endl;
          cout &lt;&lt; "Please re-enter customer's name:" &lt;&lt; endl;
          cin.clear();                                            
          cin.ignore(20, '\n');
      }
  
      return name[i];    
  }
  
  int main()
  { 
      string name[10];
      int i=0;
      char newentry='n';
  
      do{
          cout &lt;&lt; "Plase enter customer's name: " &lt;&lt; endl;                                                        
          getline(cin, name[i]);  
          name[i]=validateName(name, i);
  
          i++
  
          cout &lt;&lt; "Would you like to enter another questionare? Enter either 'y' or 'n': " &lt;&lt; endl;
          cin &gt;&gt; newentry;
  
      } while((newentry =='y') || (newentry=='Y'));
  </code></pre>
  
  <p>The function seems to do the job fine, but only with the first input. For example when I run the program and enter a number 3, an error message will be displayed and user is asked to enter name again. After user enters a valid name, the program however keeps asking for a new input with the same error messages even if no digits or special characters are used.</p>