(1) from.html :
<html>
<head>
<title>simple web page</title>
</head>
<body>
<form action="validation.php" method="post">
Name <input type="text" name="name">
phone<input type="text" name="phone">
Email<input type="text" name="email">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
(2)validation.php :
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$regex = "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$^";
$errormsg=array();
if(!preg_match( $regex, $email ))
{
$errormsg="enter your valid email";
}
if($email=="")
{
$errormsg="enter your email ";
}
if(strlen($phone>10))
{
$errormsg="enter only 10 digit";
}
if($phone=="")
{
$errormsg="enter your phone ";
}
if (!is_numeric($phone))
{
echo 'it is not numeric';
}
if($name=="")
{
$errormsg="enter your Name ";
}
if(empty($errormsg))
{
echo "form filled properly";
}
else
{
echo $errormsg;
}
?>
<html>
<head>
<title>simple web page</title>
</head>
<body>
<form action="validation.php" method="post">
Name <input type="text" name="name">
phone<input type="text" name="phone">
Email<input type="text" name="email">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
(2)validation.php :
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$regex = "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$^";
$errormsg=array();
if(!preg_match( $regex, $email ))
{
$errormsg="enter your valid email";
}
if($email=="")
{
$errormsg="enter your email ";
}
if(strlen($phone>10))
{
$errormsg="enter only 10 digit";
}
if($phone=="")
{
$errormsg="enter your phone ";
}
if (!is_numeric($phone))
{
echo 'it is not numeric';
}
if($name=="")
{
$errormsg="enter your Name ";
}
if(empty($errormsg))
{
echo "form filled properly";
}
else
{
echo $errormsg;
}
?>
No comments:
Post a Comment