title: Java - Check if a date is valid for a given dateformat
body: <p>I have the following code to check if a given date is valid </p>
  
  <pre><code>SimpleDateFormat fromformatter = new SimpleDateFormat("MMYY");
  fromformatter.setLenient(false);
  
  try {
      fromformatter.parse(dateString);
      valuesQuery.append("'" + dateString+ "',");
  } catch (ParseException pe) {
      pe.printStackTrace();
      valuesQuery.append("'notDate" + dateString+ "',");
  }
  </code></pre>
  
  <p>Now, when I get <code>dateString = "1803";</code> which is not a valid date, no exception is thrown. The date format that is being used here is <code>MMYY</code>. </p>
  
  <p>What am i doing wrong? </p>
  
  <p>Note that a regex will not help me as the date format will change.</p>