nealios Posted March 17, 2008 Share Posted March 17, 2008 Hello, How can i validate a date field to ensure that you can only enter a date into mmddyyyy format standard to mysql date data type? Ive been validating other fields in the style below then outputting the message on back on my form page. Can anyone help me sort the date validation out? if (!is_numeric($telephone)) { $message7 = "Please ensure numeric"; header("Location: newcustomer.php?message7=$message7"); exit(); } if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $message8 = "Please email is in the right format"; header("Location: newcustomer.php?message8=$message8"); exit(); } Link to comment https://forums.phpfreaks.com/topic/96631-php-date-validation/ Share on other sites More sharing options...
OkBoy Posted March 18, 2008 Share Posted March 18, 2008 Sorry, posted in wrong thread. Mods, feel free to delete. Link to comment https://forums.phpfreaks.com/topic/96631-php-date-validation/#findComment-494512 Share on other sites More sharing options...
thebadbad Posted March 18, 2008 Share Posted March 18, 2008 I like how you have a regex for an email, but can't figure out the simple date one I would go with this (read this article if you want some insight): <?php if (!eregi('^(0[1-9]|1[012])([012][1-9]|3[01])([012][0-9]{3})$', $date)) { // set error message } ?> I haven't tested it, but hope it works. I set the year part to range between 0000 and 2999, just ask if you want it differently. Link to comment https://forums.phpfreaks.com/topic/96631-php-date-validation/#findComment-494538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.