PHP date validation

PHP date validation


Posted in : PHP Posted on : February 2, 2011 at 6:33 PM Comments : [ 0 ]

In this tutorial you will learn how to use PHP date validation in a PHP web application.

PHP date validation

In this tutorial you will learn how to use PHP date validation in a PHP web application. In this tutorial  checkdate() function that check date valid or not.  The code of "php-date-validation.php" given below :

<?php
$error_message="";
if(isset($_POST['submit'])){
$date=$_POST['date'];
if($date!=""){
$date_split=explode('-',$date);
$mm=$date_split[1];
$dd=$date_split[2];
$yy=$date_split[0];
If(!checkdate($mm,$dd,$yy)){
$error_message= "invalid date";
}else{
$error_message ="date is correct";
}
}
}
?>
<HTML>
<BODY>
<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h3 align="center" >Date validation</h3>
<table align="center" >
<tr>
<td colspan="2" >
Date format('Y-m-d') :
</td>
</tr>
<tr>
<td>
Enter Date :
</td>
<td>
<input type="text" name="date" id="date" />
</td>
</tr>
<tr>
<td></td>
<td>
<?php echo $error_message; ?>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Submit" name="submit" />
</td>
</tr>
</table>
</form>
</BODY>
</HTML>

Output :

When run "php-date-validation.php" display as :

If enter any valid date in text input and click  "Submit" button then  display output as :  

If enter any invalid date in text input and click "Submit" button  then display output as :  

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics