Get Major Training|Project Training|Live Project|Industrial Training On Android| I-Phone | Java | J2SE | J2EE | C#.Net | ASP.Net| PHP | PHP with Wordpress | Joomla | Majento Contact us

Thursday

UnderStanding Using Regular Expression using PHP

Check out PHP Validation

We are providing Basic Validation using PHP

Use it in your project whenever required

      /*PHP VALIDATION SCRIPT*/
// define variables and set to empty values
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
   
    //echo "Post";
function test_input($data)
{   //echo "test call";
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
}

     //Checking Letter and Number
   if (empty($_POST["txtBtchno"]))
     {$BatchErr = "letters and  No is required";}
   else
     {
     $batch = test_input($_POST["txtBtchno"]);
     // check if name only contains letters and whitespace
     if (!preg_match("/^[a-zA-Z]{0,6}[0-9]{0,8}$/",$batch))
       {
       $BatchErr = "Only letters and Numbers allowed";
       }
    
     //Checking  Date Validation
  if (empty($_POST["txtExp"]))
     {$ExpErr = " date is required";}
   else
     {
     $exp = test_input($_POST["txtExp"]);
     // check if name only contains letters and whitespace
     if (!preg_match("/^[a-zA-Z]{3}[0-9]{4}$/",$exp))
       {
       $ExpErr = "Only date allowed";
       }
     }
     //checking number validation
  if (empty($_POST["txtAmtPic"]))
     {$AmtpicErr = "Price is required";}
   else
     {
     $ampic = test_input($_POST["txtAmtPic"]);
     // check if name only contains letters and whitespace
     if (!preg_match('/^[0-9]+$/',$ampic))
       {
       $AmtpicErr = "Only Numbers allowed";
       }
    
 
 
     }
//End of PHP Validations
     }?>
Author: Vikas Agrawal
Vikas Agrawal is a CEO and Founder Of Vinayak Informatics Systems. Read More →

You Like It, Please Share This Article Using...



No comments:

Post a Comment

Please leave your comments and we will be reply you back ASAP
vikas agrawal