It will contain a list of formats for which validation was successful.A flag in case validation was successful for more than 1 formats.My concern would be with the requirements themselves. These are some initial requirements and later i will give an option to validate against a given format/formats.
However, I'm strongly against rejecting five or more digits, as that essentially puts an expiration date on your code.
It may be early, but why introduce an unnecessary Y10K problem? Your many catch-clauses provide a detailed message, but does anyone need it? a single catch clause stating "expected MM/DD/YYYY, got ..." should do.
You catch anything that is a fails or if the year is non-positive.
If the year is between 0 and 100, it assumes that it is abbreviated and asks for more digits.
* In this scenario, there is no fixed format against which the validation is supposed to be done.
* However, with JAVA , the easiest approach is to catch a Parse Exception.
Never use strings, when something better is available.
/** * */ package home.always.learning.java; import Simple Date Format; /** * @author Tarun Trehan * @category Utility * * Code to validate if input "String" is a valid date or not.
I'm looking to increase the conciseness of this code.
I realize that I can use Joda (or Java 8's new date API), but if I were to keep this to just Java 7, any suggestions?
I wanted to know that is there any method available in Java that can do this. I have input string from user that can be any characters.