Validate Date Format
This program validates date format using regex.
Problem Statement
Write a Java program to validate date in format DD/MM/YYYY.
Source Code
| 1 | public class RegexDateValidation { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Regex Date Validation"); |
| 4 | String date="15/07/2026"; |
| 5 | String regex="^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/\\d{4}$"; |
| 6 | if(date.matches(regex)) System.out.println("Valid date format"); |
| 7 | else System.out.println("Invalid date format"); |
| 8 | } |
| 9 | } |
Program Output
Eduinq Regex Date Validation Valid date format
Explanation
Regex checks day, month, and year format. - matches() validates string. - Together demonstrates date validation. Conclusion: Shows how to validate date format using regex.