Java tutorial
//package com.java2s; public class Main { private static final String DEFAULT_DATE_REGEX = "\\b\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-2])\\b"; /** * This method checks whether the String inDate is a valid date following * the format "yyyy-MM-dd". * * @param dateString the string to be checked. * @return true/false depending on whether the string is a date according to the format "yyyy-MM-dd". */ public static boolean dateIsValid(String dateString) { return dateString.matches(DEFAULT_DATE_REGEX); } }