Hi all
How do I check that a date is entered in this format? DD/MM/YYYY
Tried below so far...
$new_date = $_POST['new_date']; ereg([0-9][0-9][/][0-1][0-9][/][2][0][0-9][0-9]);
Thanks.
You could try:
function isValidDate($date) { return preg_match('#^\d\d/\d\d/\d{4}$#', $date) && checkdate( (int)substr($date, 3, 2), (int)substr($date, 0, 2), (int)substr($date, 7, 4)); }
For a better date validator have a look at the one I use http://www.stevenmapes.com/index.php?/archives/46-Date-Validation-Function.html
It accepts dates in ISO format, but with three different separators, and validates the format as well as the date itself
if (preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $new_date)) { echo "Ok"; } else { echo "Error!"; }