Page 1 of 1

coding dought

Posted: Tue Jun 23, 2009 5:15 am
by kuttus
hello any body can help me here is an small code ..

Code: Select all

 
<?php
if(isset($_POST["submit"]))
 {
    $d=$_POST["txt_date"];
if(!filter_var($d, FILTER_VALIDATE_INT))
           {
             echo"enter only integers for date";
            }
            else
            {
            echo"entered is an integer";
            }
    }       
    ?>
    
            
    <form name="fname" method="post" action="">
 
Date: <input type="text" name="txt_date"  id="txt_date" value="" size="2"/>
<input type="submit" value="submit" name="submit" />
 

here while in the output if we r entering 01 or 02 ie any thing starting with an 0 integer is showing its not an integer and i need for my program 01,02 format where it i dont need to accept it an integer like 1r or a1 so i used filtering for it but its giving for 01 not an integer and if iwll enter 12 numbers like123456789123 it will give its not an integer why?

Re: coding dought

Posted: Tue Jun 23, 2009 6:10 am
by jayshields
I can't help you without knowing what filter_var() does exactly. You could just use is_numeric().

Please improve your English, it's difficult to understand what you're trying to say. A lot of people seem to be misspelling "doubt" as "dought" these days too.

Re: coding dought

Posted: Tue Jun 23, 2009 6:19 am
by onion2k
jayshields wrote:I can't help you without knowing what filter_var() does exactly.
It's a PHP function. Very handy for validation... http://uk3.php.net/filter_var

The problem is that integers don't have preceding zeroes. PHP removes them. It's kind of wrong that is does, but you can add them back on very easily just by checking if the number is <= 9 and concatenating a 0 on the front if it is.

Re: coding dought

Posted: Tue Jun 23, 2009 6:38 am
by jayshields
Well you learn something new everyday! I'm clearly not up to scratch with the new functions.

Re: coding dought

Posted: Tue Jun 23, 2009 7:53 am
by kuttus
jayshields wrote:I can't help you without knowing what filter_var() does exactly. You could just use is_numeric().

Please improve your English, it's difficult to understand what you're trying to say. A lot of people seem to be misspelling "doubt" as "dought" these days too.
hello here is my program just check it ok...............

Code: Select all

 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
 
<body bgcolor="#D4FFFF">
<h1 align="center">*** CIVIL ID VERIFICATION *** </h1>
<form name="fname" method="post" action="">
<br />
<table border="" cellpadding="" cellspacing="" align="center">
<tr><th>
Date: <input type="text" name="txt_date"  id="txt_date" value="" size="2"/>
Month: <input type="text" name="txt_month"  id="txt_month" value="" size="2"/>
Year: <input name="txt_year" type="text"  id="txt_year" value="" size="4" maxlength="4"/>
</th></tr>
<br />
<br /> <br/>
<tr><th>
civilID: <input name="txt_civil" type="text"" id="txt_civil" value="" size="12" maxlength="12"/>
</tr></th>
 
<br />
<br /><br />
<tr><th>
<input type="submit" value="submit" name="submit" onClick="return validation();" />
</tr></th>
</form>
</body>
</html>
 
<?
 if(isset($_POST["submit"]))
 {
   //if(isset($_POST["txt_date"]) && isset($_POST["txt_month"]) && isset($_POST["txt_year"]) && isset($_POST["txt_civil"]))
        //{
           $d=$_POST["txt_date"];
           echo"$d";
          $m=$_POST["txt_month"];
          echo"$m";
          $y=$_POST["txt_year"];
          echo"$y";
          $c=$_POST["txt_civil"];
           if(!filter_var($d, FILTER_VALIDATE_INT))
           {
             echo"enter only integers for date";
            }
            else
            {         
          if(strlen($d)!=2)
          {
              echo"Enter the date in dd format";
              echo"<br>";
          }
            else
            {
              if($d>=1 && $d<=31)
             {
              }
              else
              {  
                echo"Enter the date in between 01 and 31";
                echo"<br>";
              }
            }
            }
             if(!filter_var($m, FILTER_VALIDATE_INT))
             { 
               echo"Enter the month in integer";
               }
               else
               {
             if(strlen($m)!=2)
             {
                 echo"Enter the month in mm format";
                 echo"<br>";
             }
              else
              {
                if($m>=1 && $m<=12)
                {
                  }
                  else
                  {
                    echo"Enter the month in between 01 and 12";
                    echo"<br>";
                  } 
                
              } 
             }
             if(!filter_var($y, FILTER_VALIDATE_INT))
             {
               echo"enter the year in integer";
              }
              else
              {  
              if(strlen($y)!=4)
                {
                  echo"Enter the year in yyyy format";
                  echo"<br>";
                }
            else
                {
                  if($y>=1800 && $y<=2099)
                   {
                    }
                    else
                     {
                       echo"Enter the year in between 1800 and 2099";
                        echo"<br>";
                      }
                }
                }
                if(!filter_var($c, FILTER_VALIDATE_INT))
                  {
                   echo"enter only the integers for civilid ";
                  }
                  else
                  {             
                   if(strlen($c)!=12)
                   {
                      echo"Enter the civil id correctly";
                      echo"<br>";
                   }
                   else
                   {
                      if(strlen($c)>12)
                      {
                        echo"Enter the civil id correctly";
                         echo"<br>";
                      }
                        else
                        { 
                          validateid($_POST["txt_civil"],$_POST["txt_date"],$_POST["txt_month"],$_POST["txt_year"]);
                         }
                   }
        }          }     
               function validateid($c,$d,$m,$y)
               {
                  if (CInt($u) == $c)
                       $century=$u[0];
                          
                            if ($century == "1") $y += 1800;
                                  else if ($century == "2") $y += 1900;
                                  else if ($century == "3") $y += 2000;
                                  else{echo"invalid civil id";}
       //year position in civil id tag
                                       $k=substr($y,-2);
                                       $a=$k;
                                       if($u[1].$u[2]==$a)
                                           {}
                                       else
                                    {
                                         echo"invalid civil id number";
                                     } 
       //month position in civil id tag
                                         $l=$m;
                                       if($u[3].$u[4]==$l)
                                         {}
                                         else
                                        {
                                          echo"invalid civil id";
                                        }
       
       //date position in civil id tag
                                    $n=$d;
                                         if($u[5].$u[6]==$n)
                                            {}
                                        else
                                      {
                                          echo"invalid civil id";
                                      } 
                                         $s=$u[7].$u[8].$u[9].$u[10].$u[11];
                                         if(strlen($s)!=5)
                                      {
                                          echo"invalid civil id number";
                                       }   
                                      else{
                                          if($s>=00001 && $s<=99999)
                                             {}
                                         else
                                             {
                                                echo"invalid civil id number";
                                             }
                                          }
                          echo"Valid Civil ID Thank U FOR Checking";
                 }                         
          
                
            //}
            
            ?>
            
            <script type="text/javascript">
function validation()
{
 
 
    if (document.getElementById('txt_date').value== "")
    {
        alert('Enter date');
        document.getElementById('txt_date').focus();
        return false;
    }
    if (document.getElementById('txt_month').value== "")
    {
        alert('Enter month');
        document.getElementById('txt_month').focus();
        return false;
    }
    if (document.getElementById('txt_year').value== "")
    {
        alert('Enter year');
        document.getElementById('txt_year').focus();
        return false;
    }
    if (document.getElementById('txt_civil').value== "")
    { 
        alert('Enter civil');
        document.getElementById('txt_civil').focus();
        return false;
    }
}
 
</script>

Re: coding dought

Posted: Tue Jun 23, 2009 7:54 am
by kuttus
onion2k wrote:
jayshields wrote:I can't help you without knowing what filter_var() does exactly.
It's a PHP function. Very handy for validation... http://uk3.php.net/filter_var

The problem is that integers don't have preceding zeroes. PHP removes them. It's kind of wrong that is does, but you can add them back on very easily just by checking if the number is <= 9 and concatenating a 0 on the front if it is.
here is program which i have done

Code: Select all

 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
 
<body bgcolor="#D4FFFF">
<h1 align="center">*** CIVIL ID VERIFICATION *** </h1>
<form name="fname" method="post" action="">
<br />
<table border="" cellpadding="" cellspacing="" align="center">
<tr><th>
Date: <input type="text" name="txt_date"  id="txt_date" value="" size="2"/>
Month: <input type="text" name="txt_month"  id="txt_month" value="" size="2"/>
Year: <input name="txt_year" type="text"  id="txt_year" value="" size="4" maxlength="4"/>
</th></tr>
<br />
<br /> <br/>
<tr><th>
civilID: <input name="txt_civil" type="text"" id="txt_civil" value="" size="12" maxlength="12"/>
</tr></th>
 
<br />
<br /><br />
<tr><th>
<input type="submit" value="submit" name="submit" onClick="return validation();" />
</tr></th>
</form>
</body>
</html>
 
<?
 if(isset($_POST["submit"]))
 {
   //if(isset($_POST["txt_date"]) && isset($_POST["txt_month"]) && isset($_POST["txt_year"]) && isset($_POST["txt_civil"]))
        //{
           $d=$_POST["txt_date"];
           echo"$d";
          $m=$_POST["txt_month"];
          echo"$m";
          $y=$_POST["txt_year"];
          echo"$y";
          $c=$_POST["txt_civil"];
           if(!filter_var($d, FILTER_VALIDATE_INT))
           {
             echo"enter only integers for date";
            }
            else
            {         
          if(strlen($d)!=2)
          {
              echo"Enter the date in dd format";
              echo"<br>";
          }
            else
            {
              if($d>=1 && $d<=31)
             {
              }
              else
              {  
                echo"Enter the date in between 01 and 31";
                echo"<br>";
              }
            }
            }
             if(!filter_var($m, FILTER_VALIDATE_INT))
             { 
               echo"Enter the month in integer";
               }
               else
               {
             if(strlen($m)!=2)
             {
                 echo"Enter the month in mm format";
                 echo"<br>";
             }
              else
              {
                if($m>=1 && $m<=12)
                {
                  }
                  else
                  {
                    echo"Enter the month in between 01 and 12";
                    echo"<br>";
                  } 
                
              } 
             }
             if(!filter_var($y, FILTER_VALIDATE_INT))
             {
               echo"enter the year in integer";
              }
              else
              {  
              if(strlen($y)!=4)
                {
                  echo"Enter the year in yyyy format";
                  echo"<br>";
                }
            else
                {
                  if($y>=1800 && $y<=2099)
                   {
                    }
                    else
                     {
                       echo"Enter the year in between 1800 and 2099";
                        echo"<br>";
                      }
                }
                }
                if(!filter_var($c, FILTER_VALIDATE_INT))
                  {
                   echo"enter only the integers for civilid ";
                  }
                  else
                  {             
                   if(strlen($c)!=12)
                   {
                      echo"Enter the civil id correctly";
                      echo"<br>";
                   }
                   else
                   {
                      if(strlen($c)>12)
                      {
                        echo"Enter the civil id correctly";
                         echo"<br>";
                      }
                        else
                        { 
                          validateid($_POST["txt_civil"],$_POST["txt_date"],$_POST["txt_month"],$_POST["txt_year"]);
                         }
                   }
        }          }     
               function validateid($c,$d,$m,$y)
               {
                  if (CInt($u) == $c)
                       $century=$u[0];
                          
                            if ($century == "1") $y += 1800;
                                  else if ($century == "2") $y += 1900;
                                  else if ($century == "3") $y += 2000;
                                  else{echo"invalid civil id";}
       //year position in civil id tag
                                       $k=substr($y,-2);
                                       $a=$k;
                                       if($u[1].$u[2]==$a)
                                           {}
                                       else
                                    {
                                         echo"invalid civil id number";
                                     } 
       //month position in civil id tag
                                         $l=$m;
                                       if($u[3].$u[4]==$l)
                                         {}
                                         else
                                        {
                                          echo"invalid civil id";
                                        }
       
       //date position in civil id tag
                                    $n=$d;
                                         if($u[5].$u[6]==$n)
                                            {}
                                        else
                                      {
                                          echo"invalid civil id";
                                      } 
                                         $s=$u[7].$u[8].$u[9].$u[10].$u[11];
                                         if(strlen($s)!=5)
                                      {
                                          echo"invalid civil id number";
                                       }   
                                      else{
                                          if($s>=00001 && $s<=99999)
                                             {}
                                         else
                                             {
                                                echo"invalid civil id number";
                                             }
                                          }
                          echo"Valid Civil ID Thank U FOR Checking";
                 }                         
          
                
            //}
            
            ?>
            
            <script type="text/javascript">
function validation()
{
 
 
    if (document.getElementById('txt_date').value== "")
    {
        alert('Enter date');
        document.getElementById('txt_date').focus();
        return false;
    }
    if (document.getElementById('txt_month').value== "")
    {
        alert('Enter month');
        document.getElementById('txt_month').focus();
        return false;
    }
    if (document.getElementById('txt_year').value== "")
    {
        alert('Enter year');
        document.getElementById('txt_year').focus();
        return false;
    }
    if (document.getElementById('txt_civil').value== "")
    { 
        alert('Enter civil');
        document.getElementById('txt_civil').focus();
        return false;
    }
}
 
</script>
 

Re: coding dought

Posted: Tue Jun 23, 2009 7:55 am
by jayshields
kuttus wrote:hello here is my program just check it ok...............
Are you joking? Put it in the correct BBCode tags and trim out all the irrelevant bits and you have a better chance of receiving help.