Click here to Skip to main content
13,554,469 members
Rate this:
 
Please Sign up or sign in to vote.
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 18-Feb-18 21:17pm
Updated 19-Feb-18 15:14pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You are comparing the boolean PHP: isset - Manual[^] return value with an empty string.
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).
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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>";}
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.180515.1 | Last Updated 19 Feb 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100