The try catch block is required to handle cases where we have junk data in the middle of the date string (ex: 2015abc123) and any other invalid dates.
The Validate a Date snippet demonstrates validating a date based on a date range that the user enters.
In this example, the user selects a date from a calendar and then specifies the start and end dates to validate the specified date against.
The objective of this technique is to notify the user when user input to a field that requires a specific, required format (e.g., date fields) is not submitted in that format.
If the required format is not used, an alert dialog describes the nature of the error in text.
Once the user dismisses the alert dialog, it may be helpful if the script positions the keyboard focus on the field where the error occurred, although some users may expect the focus to remain on the last control focused prior to the alert appearing.