Java code for validating date

Let’s try to include some rules as well like month cannot be less than 1 and more than 12 and day cannot be less than 1 and more than 31.Here is the updated pattern pattern means any one of (a) 0 and any digit between 1 and 9 (b) 1 or 2 followed by any digit between 0 and 9 (c) 3 followed by either 0 or 1.Need to import the following packages first: import The parse Object method in the various Format classes requires a Parse Position object as an argument.set Display Effective Date1 :: date = 26/11/1952 set Display Effective Date2 :: date = 26/11/1952 set Display Effective Date3 :: date Format = dd-MMM-yyyy set Display Effective Date3 :: date Format = dd.It loops until the length of the inputted letters equals to the length of secret word.Enter a letter to guess: 1 Enter a letter to guess: 2 Enter a letter to guess: H Enter a letter to guess: e Enter a letter to guess: l Enter a letter to guess: l Enter a letter to guess: o You are correct!I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA.

If above list does not include the format you want to validate, you can easily modify any of the above given regex to suit your needs.

But how about input date string “2015-55-34” or “2015-99-99”?

Well, even though the dates are wrong, both of them will pass our date validation regex because it is syntactically correct.

This part will take care of the day part and will not allow anything less than 01 and more than 31.

Here is the example program using above given pattern.

Search for java code for validating date:

java code for validating date-5

Leave a Reply

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

One thought on “java code for validating date”