Commit 2b94911
committed
feat: Add regex validation to check date format (dd/MM/yyyy)
- Implements Java logic using regular expressions to validate a string as a date.
- Target format: "dd/MM/yyyy", where:
- `[0-3][0-9]` matches day values from 00 to 39 (loose check, but sufficient for basic validation).
- `/` is a literal separator.
- `[01][0-9]` matches month values from 00 to 19 (again, not strictly bounded to 12).
- `[0-9]{4}` ensures the year has exactly 4 digits.
- Used `String.matches()` to apply the regex to the input `"01/01/2000"`.
📝 Notes:
- This regex is *syntactically* valid for date format but doesn't enforce logical constraints (e.g., February can't have 31 days).
- For stricter validation (like checking leap years or correct day-month combinations), use date parsing libraries (e.g., `SimpleDateFormat` or `LocalDate` with exception handling).
Signed-off-by: Somesh diwan <[email protected]>1 parent 0551e82 commit 2b94911
File tree
1 file changed
+4
-5
lines changed- Section6StringClassPrinting/src
1 file changed
+4
-5
lines changedLines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 5 | + | |
| 6 | + | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
| |||
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
| 16 | + | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
| |||
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | | - | |
| 29 | + | |
0 commit comments