Java Check Date Format Example

Chapter: Regular Expression Last Updated: 14-09-2016 18:42:47 UTC

Program:

            /* ............... START ............... */
                
public class JavaCheckDateFormat {

	public static void main(String[] argv) {
		boolean isDate = false;
		String date1 = "8-05-1988";
		String date2 = "08/04/1987";
		String datePattern = "\\d{1,2}-\\d{1,2}-\\d{4}";
		isDate = date1.matches(datePattern);
		System.out.println(
				"Date :" + date1 + ": matches with the "
						+ "this date " + "Pattern:" + datePattern + "Ans:" + isDate);
		isDate = date2.matches(datePattern);
		System.out.println(
				"Date :" + date2 + ": matches with " + "the "
						+ "this date Pattern:" + datePattern + "Ans:" + isDate);
	}
}
                /* ............... END ............... */
        

Output

Date :8-05-1988: matches with the this date Pattern:\d{1,2}-\d{1,2}-\d{4}Ans:true
Date :08/04/1987: matches with the this date Pattern:\d{1,2}-\d{1,2}-\d{4}Ans:false

Tags

Check Date Format Example, Java, Regular Expression

Similar Programs Chapter Last Updated
Java Regular Expression Match Single Digit Regular Expression 15-12-2016
Java Regular Expression To Check Number With Dot Separator And Two Decimal Regular Expression 14-12-2016
Java Regular Expression To Check Numeric Regular Expression 14-12-2016
Java Regular Expression Digit Only Regular Expression 14-12-2016
Java Validate email Address Regular Expression 13-09-2016
Java Replace All Occourances Of String Example Regular Expression 13-09-2016
Java Make First Letter Of Each Word In Uppercase Regular Expression 13-09-2016
Java Match Phone Numbers Using Regular Expression Regular Expression 11-09-2016
Java Last Index Of Word Using Regular Expression Regular Expression 11-09-2016
Java Find Word Occurrence Using Regular Expression Regular Expression 11-09-2016
Java Splitting String Using Regular Expression Regular Expression 11-09-2016
Java Regex Pattern Split Example Regular Expression 21-06-2016
IP Address From String In Java Regex Regular Expression 21-07-2016
Validate UserName Using Regular Expression In Java Regular Expression 22-09-2018
Java Regex IP Address Example Regular Expression 21-07-2016
Regular Expression In Java Example Regular Expression 09-07-2016
Pattern Matching In Java Example Regular Expression 09-07-2016

1