Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i dont can to validation time, i use 3 text box, for hours, minutes, seconds

What I have tried:

$time=$_POST["time_tlp"];
	$menit=$_POST["menit_tlp"];
	$detik=$_POST["detik_tlp"];
	$jam_tlp = $_POST['time_tlp'].':'.$_POST['menit_tlp'].':'.$_POST['detik_tlp'];


if (isset($_POST['time_Tlp']  ) == ""  || !is_numeric($_POST['time_Tlp'])	|| ($_POST['time_Tlp'])>=23 ){
echo "<script>alert(' format jam salah ');window.history.go(-1);</script>";}
// $time = ( $_POST['jam_tlp'] );


elseif (isset($_POST['menit_tlp'] ) == ""  || !is_numeric($_POST['menit_tlp']) || ($_POST['menit_tlp'])>=59){
echo "<script>alert(' format menit salah ');window.history.go(-1);</script>";}
//$menit = ( $_POST['menit_tlp'] );



elseif (isset($_POST['detik_tlp'] ) == ""  || !is_numeric($_POST['detik_tlp']) || ($_POST['detik_tlp'])>=59){
echo "<script>alert(' format detik salah ');window.history.go(-1);</script>";}
	//$detik = ( $_POST['detik_tlp'] );
Posted
Updated 19-Feb-18 15:14pm

You are comparing the boolean PHP: isset - Manual[^] return value with an empty string.
PHP
if (isset($_POST['time_Tlp']  ) == "" 
which is never true.

PHP: is_numeric - Manual[^] checks for any valid numeric value which includes floating point numbers and negative values which are also invalid for your case. A better solution would be using PHP: intval - Manual[^]. But note that you have to handle the special cases "0" and "00" then.

Note also that the value 59 is valid (so use > 59 or >= 60).
 
Share this answer
 
its work

if (isset($_POST['time_tlp'] )== ""  || !is_numeric($_POST['time_tlp'])	|| ($_POST['time_tlp'])>=23) {
echo "<script>alert(' format jam salah ');window.history.go(-1);</script>";}


elseif (isset($_POST['menit_tlp'] ) == ""  || !is_numeric($_POST['menit_tlp']) || ($_POST['menit_tlp'])>=59){
echo "<script>alert(' format menit salah ');window.history.go(-1);</script>";}


elseif (isset($_POST['detik_tlp'] )== ""   || !is_numeric($_POST['detik_tlp']) || ($_POST['detik_tlp'])>=59){
echo "<script>alert(' format detik salah ');window.history.go(-1);</script>";}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900