Jump to content

validate input text for dates


ali_2kool2002

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.