ali_2kool2002 Posted March 3, 2007 Share Posted March 3, 2007 hi does ne 1 know how to validate a text input to make sure its in correct format so it can go into my databse straight once submitted? Link to comment https://forums.phpfreaks.com/topic/41012-validate-input-text-for-dates/ Share on other sites More sharing options...
ted_chou12 Posted March 3, 2007 Share Posted March 3, 2007 formats should be : Y-m-d H:i:s $input = $_POST['time']; $parts = expode(" ", $input); $dates = explode("-", $parts[0]); if (strlen($dates[0]) != 4 && is_int($dates[0]) != true)) {$invalid = true;}//years 4 digits if (strlen($dates[1]) != 2 && is_int($dates[1]) != true)) {$invalid = true;}//months 2 digits if (strlen($dates[2]) != 2 && is_int($dates[2]) != true)) {$invalid = true;}//days 2 digits $times = explode(":", $parts[1]); if (strlen($times[0]) != 2 && is_int($times[0]) != true)) {$invalid = true;}//hours 2 digits if (strlen($times[1]) != 2 && is_int($times[1]) != true)) {$invalid = true;}//miniutes 2 digits if (strlen($times[2]) != 2 && is_int($times[2]) != true)) {$invalid = true;}//seconds 2 digits if ($invalid == true) {echo "format invalid";} Ted Link to comment https://forums.phpfreaks.com/topic/41012-validate-input-text-for-dates/#findComment-198596 Share on other sites More sharing options...
ted_chou12 Posted March 3, 2007 Share Posted March 3, 2007 hello, does: <?php $input = $_POST['time']; $parts = expode(" ", $input); $dates = explode("-", $parts[0]); if (strlen($dates[0]) != 4 && is_int($dates[0]) != true) {$invalid = true;}//years 4 digits if (strlen($dates[1]) != 2 && is_int($dates[1]) != true) {$invalid = true;}//months 2 digits if (strlen($dates[2]) != 2 && is_int($dates[2]) != true) {$invalid = true;}//days 2 digits $times = explode(":", $parts[1]); if (strlen($times[0]) != 2 && is_int($times[0]) != true) {$invalid = true;}//hours 2 digits if (strlen($times[1]) != 2 && is_int($times[1]) != true) {$invalid = true;}//miniutes 2 digits if (strlen($times[2]) != 2 && is_int($times[2]) != true) {$invalid = true;}//seconds 2 digits if ($invalid == true) {echo "format invalid";} ?> work? Ted Link to comment https://forums.phpfreaks.com/topic/41012-validate-input-text-for-dates/#findComment-198615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.