<?php /* Online PHP Examples with Source Code website: http://4evertutorials.blogspot.in/ */ $date = '2013-06-27'; function isValidDate($date) { if(preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $date, $matches)) { if(checkdate($matches[2], $matches[3], $matches[1])) { return true; } } } if(isValidDate($date)){ echo 'valid date'; } else { echo 'invalid date'; } ?>
Date Validation dd-mm-yyyy
<?php /* Online PHP Examples with Source Code website: http://4evertutorials.blogspot.in/ */ $date = '27-06-2013'; function isValidDate($date) { if(preg_match("/^(\d{2})-(\d{2})-(\d{4})$/", $date, $matches)) { if(checkdate($matches[2], $matches[1], $matches[3])) { return true; } } } if(isValidDate($date)) { echo 'valid date'; } else { echo 'invalid date'; } ?>
Date Validation mm-dd-yyyy
<?php /* Online PHP Examples with Source Code website: http://4evertutorials.blogspot.in/ */ $date = '06-27-2013'; function isValidDate($date) { if(preg_match("/^(\d{2})-(\d{2})-(\d{4})$/", $date, $matches)) { if(checkdate($matches[1], $matches[2], $matches[3])) { return true; } } } if(isValidDate($date)){ echo 'valid date'; } else { echo 'invalid date'; } ?>
Date Validation dd-mmm-yyyy
<?php /* Online PHP Examples with Source Code website: http://4evertutorials.blogspot.in/ */ $date = '27-Jun-2013'; function isValidDate($date) { if(preg_match("/^(\d{2})-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d{4})$/", $date, $matches)) { $month = array('Jan'=>'01' ,'Feb'=>'02' ,'Mar'=>'03' ,'Apr'=>'04' ,'May'=>'05' ,'Jun'=>'06' ,'Jul'=>'07' ,'Aug'=>'08' ,'Sep'=>'09' ,'Oct'=>'10' ,'Nov'=>'11' ,'Dec'=>'12' ); if(checkdate($month[$matches[2]],$matches[1],$matches[3])) { return true; } } } if(isValidDate($date)) { echo 'valid date'; } else { echo 'invalid date'; } ?>
0 comments:
Post a Comment