Java code for validating date

Make a boolean in the beginning called like is True Date, make it true, and if one of the conditions occur to make it not a true date, set it to false. Use Joda Time API; and instantiate the Date Time class object by the given input.If the input date is not correct/invalid; it will throw exception.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.Input : d = 10, m = 12, y = 2000 Output : Yes The given date 10/12/2000 is valid Input : d = 30, m = 2, y = 2000 Output : No The given date 30/2/2000 is invalid. Here we want to use a regex that simply checks whether the input is a valid date without trying to eliminate things such as February 31st.We might think that something as conceptually trivial as a date validation should be an easy job for a regular expression. The main issue is that regular expressions don’t deal directly with numbers.First I’ll show you how to validate date using java regex in US format and later I’ll show you how that same logic can be applied to validate date in English format (used in most countries outside North America).

This purpose of this post is to provide step-by-step guidance to develop a utility that will have the following functionality: 1) This utility will help to validate a date format entered by the user.

This is the code I have so far, I've been using if/else statements which I know are not efficient but since I am a beginner at java it did not matter much to me. You don't tell us what data causes the "return nothing" behavior you describe, but it looks to me like many of the times that don't pass your tests do a return statement out of main() without printing anything.

The program works fine for certain checks but when it doesn't it skips most of my code and doesn't return anything. For example: Don't use return inside the if statements that's your problem.

The program outputs whether or not the input represents a valid date.

Keep in mind that April, June, September, and November have 30 days, February has either 28 or 29 days (depending on whether it is a leap year), and the other months have 31 days.

2) If the user entered data is valid then it will be convertible to a format that can be easily inserted into the database.

You must have an account to comment. Please register or login here!