Today Here, I would like to share one useful as well as important information about Email and mobile verification using PHP script. In the past, We were using form validation on Jquery and Javascript but now you can see that how form validation be done in PHP. Let discuss about the code to get it done.
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,
)
Check out the below code in 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 </label>
<input type="text" name="email" /><br />
<label>Phone</label>
<input type="text" name="phone" /><br />
<input type="submit" name="submit" value="submit" />
</form>
Email & mobile number validation script in PHP
Click Here to Download The Code
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,
)
Check out the below code in 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 </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