title: Correct way to validate user input in Python
body: <p>I am working my way through some Python tutorials one of the things that keeps coming up is user input and i just wanted to check that i am validating it correctly and not going about it the long way around.</p>
  
  <p>I have written the code below and only need to ask for the day month and year but if i needed to start asking for address phone number name etc etc this would grow and grow is that normal?</p>
  
  <pre><code>def get_input( i ):
  
      while True:
          # We are checking the day
          if i == 'd':
              try:
                  day = int( raw_input( "Please Enter the day: " ) )
                  # If the day is not in range reprint
                  if day &gt; 0 and day &lt; 32:
                      #Need to account for short months at some point
                      return day
                  else:
                      print 'it has to be between 1 and 31'
              except ( ValueError ):
                  print "It has to be a number!"
          elif i == 'm':
              # We are checking the month
              month = raw_input( 'Please enter ' +
                                'in words the month: '
                                ).strip().lower()
              if month in months: # use the dict we created
                  return month
              else:
                  print 'Please check you spelling!'
          elif i == 'y':
              # Now the year
              try:
                  year = int( raw_input( "Please Enter the year" +
                                         "pad with 0's if needed: " ) )
                  #make we have enough digits and a positive
                  if year &gt; 0 and len( year ) == 4:
                      return year
              except ( ValueError, TypeError ):
                      print "It has to be a four digit number!"
  </code></pre>