1<?php
2// First Verif your regex code with https://regex101.com/
3$str = "Visit W3Schools";
4$pattern = "/w3schools/i";
5echo preg_match($pattern, $str); // Outputs 1
6
7// test email with REGEX
8if (!preg_match("/[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+.[a-zA-Z]{2,4}/", $emailAddress)){
9 //Email address is invalid.
10}
11
12// use filter var to valide Email
13if(filter_var($emailAddress, FILTER_VALIDATE_EMAIL))
14{
15 //The email address is valid.
16} else{
17 //The email address is invalid.
18}
19
20
21?>
22