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
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.
 }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.