Jump to content

[SOLVED] is_numeric not working


adam291086

Recommended Posts

I have some script that is taking an entered day dd/mm/yyyy. Spliting it up into dd mm and yyyy. Then checking if dd/mm/yyyy is entered in with /. then i am trying to check if it contains number. All i get is the echoed error message. Can anyone point me in the right direction

 

<?php

if ($_POST)
{
error_reporting(E_ALL);

//get the variables

$title = $_POST['title'];
$description = $_POST['description'];
$date = $_POST['date'];

//search for / in day, month and year


$findme    = '/';
$date1 = strpos($date, $findme);


// Nope, 'a' is certainly not in 'xyz'
if ($date1 === false) {
    echo "The date must have the format dd/mm/yyyy";
}


if ($date1 !== false) {



//get the day, month and year

$date = explode("/", $date);
$day = $date[0];
$month = $date[1];
$year = $date[2];


}

if (is_numeric($day && $month && $year)) {
echo "Event Added Successfully";
} 
else {
echo "Invalid date entry. Please try again";
}




//end if at start
} 


?>

 

I have done some debugging and all the vairbles from the form are being posted

Link to comment
https://forums.phpfreaks.com/topic/82187-solved-is_numeric-not-working/
Share on other sites

You would be much better off using one simple regex. I'm not much good at them, but this might go close. Ask your question in the regx board if you get stuck.

 

<?php

 $date = $_POST['date'];
 if (preg_match('/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/',$date) {
   // valid.
 }

?>

Here is the one I used

 

^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/(\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/(\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/(\d{2}))|(29\/02\/((0[48]|[2468][048]|[13579][26])|(00))))$

 

Found at

 

http://regexlib.net/REDetails.aspx?regexp_id=488

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.