Validate drop down month , day , year
User Jquery :
var year=$("#year").attr('value');
var month=$("#month").attr('value');
var day=$("#day").attr('value');
var data="year="+year+"&month="+month+"&day="+day;
$.ajax({
type:"get",
url:"<?php echo HTTP_ROOT;?>validate/validDate?"+data,
success: function(resp){
if(resp=="false"){
alert("Success");
}else{
alert("False");
}
Php function method
function validate()
{
$day=$_GET['day'];
$month=$_GET['month'];
$year=$_GET['year'];
if(is_numeric($day) && is_numeric($month) && is_numeric($year))
{
if($year%4==0)
{
if($month==01 || $month==03 || $month==05 || $month==07 || $month==08 || $month==10 || $month==12)
{
echo "true";
}
else if($month==04 || $month==06 || $month==09 || $month==11 || $month==08)
{
if($day<=30)
{
echo "true";
}else
{
echo "false";
}
}
else
{
if($day<=29)
{
echo "true";
}
else
{
echo "false";
}
}
} else {
if($month==01 || $month==03 || $month==05 || $month==07 || $month==08 || $month==10 || $month==12)
{
echo "true";
} else if($month==04 || $month==06 || $month==09 || $month==11 || $month==08)
{
if($day<=30)
{
echo "true";
}else{
echo "false";
}
}else{
if($day<=28)
{
echo "true";
}else{
echo "false";
}
}
}
} else {
echo "false";
}
die;
}
User Jquery :
var year=$("#year").attr('value');
var month=$("#month").attr('value');
var day=$("#day").attr('value');
var data="year="+year+"&month="+month+"&day="+day;
$.ajax({
type:"get",
url:"<?php echo HTTP_ROOT;?>validate/validDate?"+data,
success: function(resp){
if(resp=="false"){
alert("Success");
}else{
alert("False");
}
Php function method
function validate()
{
$day=$_GET['day'];
$month=$_GET['month'];
$year=$_GET['year'];
if(is_numeric($day) && is_numeric($month) && is_numeric($year))
{
if($year%4==0)
{
if($month==01 || $month==03 || $month==05 || $month==07 || $month==08 || $month==10 || $month==12)
{
echo "true";
}
else if($month==04 || $month==06 || $month==09 || $month==11 || $month==08)
{
if($day<=30)
{
echo "true";
}else
{
echo "false";
}
}
else
{
if($day<=29)
{
echo "true";
}
else
{
echo "false";
}
}
} else {
if($month==01 || $month==03 || $month==05 || $month==07 || $month==08 || $month==10 || $month==12)
{
echo "true";
} else if($month==04 || $month==06 || $month==09 || $month==11 || $month==08)
{
if($day<=30)
{
echo "true";
}else{
echo "false";
}
}else{
if($day<=28)
{
echo "true";
}else{
echo "false";
}
}
}
} else {
echo "false";
}
die;
}
No comments:
Post a Comment