LocalDateTime dateAndTime = LocalDateTime.now(); //gets current date and time
String birthdateIn = cBirthdate.getText(); //gets birthdate input
SimpleDateFormat mmddyyyy = new SimpleDateFormat("mm/dd/yyyy"); //mm/dd/yyyy formatter
mmddyyyy.setLenient(false);
try {
Date stringToDate = mmddyyyy.parse(birthdateIn);
bLabel.setForeground(Color.green);
bLabel.setText("Valid Birthdate");
}
catch (ParseException e) {
bLabel.setForeground(Color.red);
bLabel.setText("Invalid Birthdate");
}
This is the code I'm using to check for birthdate validity in JFrame, and while the checker works correctly, it validates year when I input a single integer instead of checking if it contains 4 integers. How do I correct it?
Also how do I extract the inputted birthdate to check if the user is below 18 years old?