Write a java program to validate the Date of Birth

Write a program to validate the Date of Birth given as input in String format (MM/dd/yyyy) as per the validation rules given below. Return true for valid dates else return false.
1. Value should not be null
2. month should be between 1-12, date should be between 1-31 and year should be a four digit number.

The return type is TRUE / FALSE.

Input and Output Format:
Input consists of a string.
Output consists of TRUE / FALSE.
Refer sample output for formatting specifications.

Sample Input 1:

Sample Output 1:

Sample Input 2:

Sample Output 2:

java program to validate the Date of Birth

package com.demo;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String str = new String();
Scanner sc = new Scanner(System.in);
str = sc.nextLine();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
try {
Date d1 = sdf.parse(str);
} catch (Exception e) {

Add a Comment

Your email address will not be published. Required fields are marked *

17 + thirteen =