We use java.util.regex.Pattern.compile(String regex) method which compiles the given regular expression into a pattern. Here regex is the expression to be compiled.
More ways to validate a date :
- SimpleDateFormat class. We can use parse method of this class to validate the date.
- Writing our own method to check if a date is valid.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Program to Convert Milliseconds to a Date Format in Java
- DateFormat format(Date obj) method in Java
- Extracting each word from a String using Regex in Java
- Get the first letter of each word in a string using regex in Java
- Java | Removing whitespaces using Regex
- Check if a string contains only alphabets in Java using Regex
- Count occurrences of a given character using Regex in Java
- Date after adding given number of days to the given date
- Print first letter of each word in a string using regex
- Regex Boundary Matchers in Java
- Compressing and Decompressing files using GZIP Format in java
- Java String format() with examples
- LocalDateTime format() method in Java
- Format Specifiers in Java
- Year format() method in Java with Examples
- LocalDate format() method in Java
- YearMonth format() method in Java
- LocalTime format() method in Java with Examples
- MonthDay format() method in Java with Examples
- OffsetDateTime format() method in Java with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.