Slip 14 - C) Using regular expressions check for the validity of entered email-id. The @ symbol should not appear more than once. The dot (.) can appear at the most once before @ and at the most twice or at least once after @ symbol. The substring before @ should not begin with a digit or underscore or dot or @ or any other special character. (Use explode and ereg function.).

Solution:

slip14.html


<html>

<body>

<form name="form1" method="post" action="slip14.php">

Enter the EmailID *<input type="text" name="email"></input>

<input type="submit" value="submit"></input>

</form>

</body>

</html>

 

 slip14.php


<?php

$email=$_POST['email'];

$regex = '/^[_a-z0-9-]+(\.[a-z0-9-]+)*@[a-z0-9]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';

if(preg_match($regex,$email)){

            echo $email .  "it is valid email id";

           

}

else

{

            echo $email ."invalid email,Please try again.";

           

}

?>

Post a Comment

0 Comments