1<?php
2   $email = "pattrick@tutorialspoint.com";
3   // Validate email
4   if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
5      echo("$email is a valid email address");
6   }
7   else{
8      echo("$email is not a valid email address");
9   }
10?>1// E-mail Code Validation using a four digit number: 
2// var.inc.php: 
3<?php 
4session_start();
5$x = mt_rand(1000,9999);
6// index.php: 
7<?php 
8include_once 'var.inc.php';
9$_SESSION['key'] = $x;
10if(isset($_POST['submit'])){
11    if(!mail($_POST['email-in'], "Verify", "Code: ". $x)){
12        echo "ERROR EMAIL";
13    }else{
14        header("Location: validate.php");
15    }
16}
17?>
18<!DOCTYPE html>
19<html lang="en">
20<head>
21    <meta charset="UTF-8">
22    <meta http-equiv="X-UA-Compatible" content="IE=edge">
23    <meta name="viewport" content="width=device-width, initial-scale=1.0">
24    <title>Validate email</title>
25</head> 
26<body>
27    <form action="" method="post">
28        <input type="email" placeholder="email" name="email-in">
29        <button id="submit" type="submit" name="submit">Submit</button>
30    </form>
31</body>
32</html>
33// validate.php: 
34  <?php session_start();?>
35<!DOCTYPE html>
36<html lang="en">
37<head>
38    <meta charset="UTF-8">
39    <meta http-equiv="X-UA-Compatible" content="IE=edge">
40    <meta name="viewport" content="width=device-width, initial-scale=1.0">
41    <title>Validate</title>
42</head>
43<body>
44    <form action="" method="post">
45        <input type="number" name="user-key">
46        <button type="submit" name="submit-user-key">Validate</button>
47    </form>
48</body>
49</html>
50<?php 
51    if(isset($_POST['submit-user-key'])){
52        if($_POST['user-key'] == $_SESSION['key']){
53            //Do something
54        }
55    }
56?>1$pattern = '/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD';
2
3$emailaddress = 'test@gmail.com';
4
5if (preg_match($pattern, $emailaddress) === 1) {
6    // emailaddress is valid
7}
8