]> git.defcon.no Git - hermes/blob - lib/check_email.php
Hermes is a framework for managing SIP-accounts, aliases and automatic phone-provisio...
[hermes] / lib / check_email.php
1 <?php
2
3 function check_email_address($email) {
4 // First, we check that there's one @ symbol,
5 // and that the lengths are right.
6 if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
7 // Email invalid because wrong number of characters
8 // in one section or wrong number of @ symbols.
9 return false;
10 }
11 // Split it into sections to make life easier
12 $email_array = explode("@", $email);
13 $local_array = explode(".", $email_array[0]);
14 for ($i = 0; $i < sizeof($local_array); $i++) {
15 if
16 (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
17 $local_array[$i])) {
18 return false;
19 }
20 }
21 // Check if domain is IP. If not,
22 // it should be valid domain name
23 if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
24 $domain_array = explode(".", $email_array[1]);
25 if (sizeof($domain_array) < 2) {
26 return false; // Not enough parts to domain
27 }
28 for ($i = 0; $i < sizeof($domain_array); $i++) {
29 if
30 (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$",
31 $domain_array[$i])) {
32 return false;
33 }
34 }
35 }
36 return true;
37 }
38 ?>