Home > Archive by category 'Email Form'
 

Email validation with Regular Expressions

This is also case-insensitive, so it will treat all characters as lower case. It is a really easy way to check the syntax and format of an email address.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<html>
<body>
<?php
if (isset($_POST['posted'])) {
   $email = $_POST['email'];
   $theresults = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $email, $trashed);   //"\w+@\w+.\w+$"
   if ($theresults) {
      $isamatch = "Valid";
   } else {
      $isamatch = "Invalid";
   }
   echo "Email address validation says $email is " . $isamatch;
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="posted" value="true">
Enter your email address for validation:
<input type="text" name="email" value="name@example.com">
<input type="submit" value="Validate">
</form>
</body>
</html>

 
 
 

Categories

Tag