note 112880 added to function.filter-var

From: Date: Thu, 01 Aug 2013 10:35:12 +0000
Subject: note 112880 added to function.filter-var
Groups: php.notes 
Request: Send a blank email to php-notes+get-195846@lists.php.net to get a copy of this message
E-mail validator function that supports IPv6 and checking length. This also supports Japanese old feature phone E-mail address by sending second argument $strict as FALSE. <?php function validate_email($email, $strict = true) { $dot_string = $strict ? '(?:[A-Za-z0-9!#$%&*+=?^_`{|}~\'\\/-]|(?<!\\.|\\A)\\.(?!\\.|@))' : '(?:[A-Za-z0-9!#$%&*+=?^_`{|}~\'\\/.-])' ; $quoted_string = '(?:\\\\\\\\|\\\\"|\\\\?[A-Za-z0-9!#$%&*+=?^_`{|}~()<>[\\]:;@,. \'\\/-])'; $ipv4_part = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'; $ipv6_part = '(?:[A-fa-f0-9]{1,4})'; $fqdn_part = '(?:[A-Za-z](?:[A-Za-z0-9-]{0,61}?[A-Za-z0-9])?)'; $ipv4 = "(?:(?:{$ipv4_part}\\.){3}{$ipv4_part})"; $ipv6 = '(?:' . "(?:(?:{$ipv6_part}:){7}(?:{$ipv6_part}|:))" . '|' . "(?:(?:{$ipv6_part}:){6}(?::{$ipv6_part}|:{$ipv4}|:))" . '|' . "(?:(?:{$ipv6_part}:){5}(?:(?::{$ipv6_part}){1,2}|:{$ipv4}|:))" . '|' . "(?:(?:{$ipv6_part}:){4}(?:(?::{$ipv6_part}){1,3}|(?::{$ipv6_part})?:{$ipv4}|:))" . '|' . "(?:(?:{$ipv6_part}:){3}(?:(?::{$ipv6_part}){1,4}|(?::{$ipv6_part}){0,2}:{$ipv4}|:))" . '|' . "(?:(?:{$ipv6_part}:){2}(?:(?::{$ipv6_part}){1,5}|(?::{$ipv6_part}){0,3}:{$ipv4}|:))" . '|' . "(?:(?:{$ipv6_part}:){1}(?:(?::{$ipv6_part}){1,6}|(?::{$ipv6_part}){0,4}:{$ipv4}|:))" . '|' . "(?::(?:(?::{$ipv6_part}){1,7}|(?::{$ipv6_part}){0,5}:{$ipv4}|:))" . ')'; $fqdn = "(?:(?:{$fqdn_part}\\.)+?{$fqdn_part})"; $local = "({$dot_string}++|(\"){$quoted_string}++\")"; $domain = "({$fqdn}|\\[{$ipv4}]|\\[{$ipv6}]|\\[{$fqdn}])"; $pattern = "/\\A{$local}@{$domain}\\z/"; return preg_match($pattern, $email, $matches) && ( !empty($matches[2]) && !isset($matches[1][66]) && !isset($matches[0][256]) || !isset($matches[1][64]) && !isset($matches[0][254]) ) ; } ?> ---- Server IP: 69.147.83.199 Probable Submitter: 219.209.194.119 ---- Manual Page -- http://php.net/manual/en/function.filter-var.php Edit -- https://master.php.net/note/edit/112880 Del: integrated -- https://master.php.net/note/delete/112880/integrated Del: useless -- https://master.php.net/note/delete/112880/useless Del: bad code -- https://master.php.net/note/delete/112880/bad+code Del: spam -- https://master.php.net/note/delete/112880/spam Del: non-english -- https://master.php.net/note/delete/112880/non-english Del: in docs -- https://master.php.net/note/delete/112880/in+docs Del: other reasons-- https://master.php.net/note/delete/112880 Reject -- https://master.php.net/note/reject/112880 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195846) next »