Monday, 20 July 2015

PHP Email and mobile number validation script

This post concept based on Email and mobile verification using in php script. Previously We using form validation on Jquery and Javascript so now check  the form validation in php. follow the below code let know as validation script.

Database
CREATE TABLE `page`
(
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  `number` varchar(50) NOT NULL,
)

PHP
Email verification function based to check on regular expression its check user email. similar on mobile number validation.

<?php
if(isset($_POST['submit']))
{  
$name=mysql_real_escape_string($_POST['name']);
$email=mysql_real_escape_string($_POST['email']);
$phone=mysql_real_escape_string($_POST['phone']);
$emailval = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/';
$mob="/^[789][0-9]{9}$/";
if(!preg_match($emailval, $email))
{
    $msg="check your email";
       
}
else
{  
if(!preg_match($mob, $phone))
{
    $msg="check your Mobile number ";
       
}  
else
{      
        if(empty($name))
    {
            $msg="Check your name so Plese Enter Again";
        }
       
        else{
           
            $ins=mysql_query("insert into page(name,email,phone) values('$name','$email','$phone')");
            if($ins)
            {
                $msg="upload succefully";
            }
           
        }
     }
  }
     echo "<span style='font-size:24px; color:Red; font-weight:600;'>$msg</span>";
  }
   ?>


HTML
<form name="form" method="post">
<label>Name</label>
<input type="text" name="name" /><br />
<label>Email &nbsp;</label>
<input type="text" name="email" /><br />
<label>Phone</label>
<input type="text" name="phone" /><br />
<input type="submit" name="submit" value="submit" />
</form>

0 comments:

Post a Comment