title: Date Validation in Android
body: <p>I'm new to Android programming and I'm currently developing an app. Can someone help me on how to validate the date that is being input by the user if is it valid or not?</p>
  
  <pre><code>private Pattern pattern;
  private Matcher matcher;
  
  private static final String DATE_PATTERN = 
         "(0?[1-9]|1[012]) [/.-] (0?[1-9]|[12][0-9]|3[01]) [/.-] ((19|20)\\d\\d)";
  
  
  /**
  * Validate date format with regular expression
  * @param date date address for validation
  * @return true valid date format, false invalid date format
  */
  public boolean validate(final String date){
  
    matcher = pattern.matcher(date);
  
    if(matcher.matches()){
        matcher.reset();
  
        if(matcher.find()){
            String day = matcher.group(1);
            String month = matcher.group(2);
            int year = Integer.parseInt(matcher.group(3));
  
            if (day.equals("31") &amp;&amp; 
             (month.equals("4") || month .equals("6") || month.equals("9") ||
                     month.equals("11") || month.equals("04") || month .equals("06") ||
                     month.equals("09"))) {
               return false; // only 1,3,5,7,8,10,12 has 31 days
            }             
        }
  
        else{
             return false;
        }        
    }
    else{
        return false;
    }              
  }
  </code></pre>