title: Not able to identify wrong date using Java regex
body: <p>I am able to identify date (mm/dd/yyyy) in a String using Java regex pattern. When I give correct date like 12/08/1947 I get 12 as month but when I put wrong date like 15/08/1947 in mm/dd/yyyy format I am getting 5 as month. Is there any way to identify wrong date? </p>
  
  <pre><code>package com.test.package;
  
  import java.io.FileNotFoundException;
  import java.text.ParseException;
  import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  
  public class DateIdentifier {
      private static final String REGEX_PATTERN = "(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])/((19|20)\\d\\d)";
  
      private static final String STR_DATA = " 99238 128.00 77.51 15/21/2017 1/01/2017 0.00 0.00 0.00 0.00 50.49  OMR/45 77.51";
  
      public static void main(String[] args) throws FileNotFoundException, ParseException {
  
          DateIdentifier dateIdentifier = new DateIdentifier();
          System.out.println(dateIdentifier.getDates(STR_DATA));
      }
  
      private boolean getDates(String strData){
          int count = 0;
          boolean flag = false;
          Matcher matcher = Pattern.compile(REGEX_PATTERN).matcher(strData);
          while(matcher.find()){
              String month = matcher.group(1);
              String day = matcher.group(2);
              int year = Integer.parseInt(matcher.group(3));
  
              if(Integer.parseInt(day)&lt;=31 &amp;&amp; !(Integer.parseInt(month)&gt;13)){
                  count +=1;
                  System.out.println("day: " +day);
                  System.out.println("month: " +month);
              }
          }
          if(count&gt;=2){
              flag = true;
          }
          return flag;
      }
  
  
  
  }
  </code></pre>