Validating date

Gregorian Calendar cal = new Gregorian Calendar(); Lenient(false); cal.set(Calendar.

I was told that the JDK class Simple Date Format() might be useful for me to use in validating dates for a program that I'm working on.

Presumably, you will have a button on the page, and when clicked, it will call the function and set the textbox's value.

The fiddle in another answer would work, but does a lot more than you were asked to do.

This still catches and rethrows the exception on non-positive years, but it doesn't discard any information in doing so.

It may be early, but why introduce an unnecessary Y10K problem?

The teacher provided a function for the actual validation, but the rest is up to me. The variables "month", "day", and "year" I put there.The main issue is that regular expressions don’t deal directly with numbers.I think there is an error in the function from bmauser below. Here's another version which also accepts missing zeros and two digits year notation.This function checks date if matches given format and validity of the date.* is_date('', 'yyyy'); // returns false * is_date('11/30/2008', 'mm/dd/yyyy'); // returns true * is_date('', 'dd-mm-yyyy'); // returns true * is_date('2008 01 30', 'yyyy mm dd'); // returns true * Super graceful solution by glavic and the mod by Bas - the only thing I would add is if you have user input, you have the potential for really munged up values for date which can throw exceptions.

Search for validating date:

validating date-51validating date-79

Add a try/catch: if (((int) $version[0] /* ## converts a given date format to another date format returns date if the checked date given is valid; otherwise returns NULL## $s_date the date in e.g.

Leave a Reply

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

One thought on “validating date”

  1. , Tally Me Bananas, All OT Prophcies Are NOT Fulfilled We have all type of personals, Christian singles, Catholic, Jewish singles, Atheists, Republicans, Democrats, pet lovers, cute Chicago women, handsome Chicago men, single parents, gay men, and lesbians. , Still love what I do., Thought this was cute (long but cute), It's That Time Of Year!