title: Validating user input (string) using Ruby
body: <p>I want to make sure that the only input from user is 8 numbers ( input will be by default integer ). </p>
  
  <p>My goal is to make sure that user is inputting date in format: yyyymmdd .</p>
  
  <p>If he won't input this format I want to use loop to make input once again until he will put correct format ( yyyymmdd ).</p>
  
  <p>My current loop does not validate the date, it passes every input. </p>
  
  <pre><code>txt=gets
  
  re1='((?:(?:[1]{1}\\d{1}\\d{1}\\d{1})|(?:[2]{1}\\d{3}))(?:[0]?[1-9]|[1][012])(?:(?:[0-2]?\\d{1})|(?:[3][01]{1})))(?![\\d])' # YYYYMMDD 1
  
  re=(re1)
  m=Regexp.new(re,Regexp::IGNORECASE);
  
  while m.match(txt) 
    txt=gets
  end
  </code></pre>