<?php
$date_of_completion = '16-03-2015';
$skip=1;
if((substr_count($date_of_completion,"-"))<>2){
$error_msg .= "<br><font color='red'>Enter the date in 'dd-mm-yyyy' format</font>";
}
else
{
$pos=strpos($date_of_completion,"-");
//Date validation
$date=substr($date_of_completion,0,($pos));
if(($date<=0)||($date>31))
{
$msg = " Date";
$skip = 0;
}
//Month validation
$month=substr($date_of_completion,($pos+1),($pos));
if(($month<=0)||($month>12))
{
if($skip ==0){
$and = ' & ';
}
$msg .= "$and Month";
$skip = 0;
}
//Year validation
$year=substr($date_of_completion,($pos+4),strlen($date_of_completion));
if(($year<=1970) || ($year>2200))
{
if($skip ==0){
$and = ' & ';
}
$msg .= "$and Year";
}
if(!empty($msg))
{
$error_msg .= "<font color='red'>Enter a valid <b>$msg or Date format</b></font>";
}
}
echo $error_msg;
?>
$date_of_completion = '16-03-2015';
$skip=1;
if((substr_count($date_of_completion,"-"))<>2){
$error_msg .= "<br><font color='red'>Enter the date in 'dd-mm-yyyy' format</font>";
}
else
{
$pos=strpos($date_of_completion,"-");
//Date validation
$date=substr($date_of_completion,0,($pos));
if(($date<=0)||($date>31))
{
$msg = " Date";
$skip = 0;
}
//Month validation
$month=substr($date_of_completion,($pos+1),($pos));
if(($month<=0)||($month>12))
{
if($skip ==0){
$and = ' & ';
}
$msg .= "$and Month";
$skip = 0;
}
//Year validation
$year=substr($date_of_completion,($pos+4),strlen($date_of_completion));
if(($year<=1970) || ($year>2200))
{
if($skip ==0){
$and = ' & ';
}
$msg .= "$and Year";
}
if(!empty($msg))
{
$error_msg .= "<font color='red'>Enter a valid <b>$msg or Date format</b></font>";
}
}
echo $error_msg;
?>
0 comments:
Post a Comment