summaryrefslogtreecommitdiff
path: root/inc/mail.php
diff options
context:
space:
mode:
authorchris <chris@jalakai.co.uk>2007-01-25 15:34:21 +0100
committerchris <chris@jalakai.co.uk>2007-01-25 15:34:21 +0100
commit0a1d30bfaabbfda6df7f79e1d0d5f616a9a2f897 (patch)
tree64ee7896d473a1f630abed5e7b53d96b9385f603 /inc/mail.php
parent2e5c161d5e38cd318c8b7846ae0b5bbf0b877e4a (diff)
downloadrpg-0a1d30bfaabbfda6df7f79e1d0d5f616a9a2f897.tar.gz
rpg-0a1d30bfaabbfda6df7f79e1d0d5f616a9a2f897.tar.bz2
improve and centralise email regexp, fixes FS#1049
darcs-hash:20070125143421-9b6ab-93ce6bfd804924af4651da9424738494f11fe5f2.gz
Diffstat (limited to 'inc/mail.php')
-rw-r--r--inc/mail.php13
1 files changed, 11 insertions, 2 deletions
diff --git a/inc/mail.php b/inc/mail.php
index a596c38f7..02434cf3c 100644
--- a/inc/mail.php
+++ b/inc/mail.php
@@ -144,14 +144,23 @@ function mail_encode_address($string,$header='',$names=true){
* Uses a regular expresion to check if a given mail address is valid
*
* May not be completly RFC conform!
+ * @link http://www.faqs.org/rfcs/rfc2822.html (paras 3.4.1 & 3.2.4)
*
- * @link http://www.webmasterworld.com/forum88/135.htm
+ * @author Chris Smith <chris@jalakai.co.uk>
*
* @param string $email the address to check
* @return bool true if address is valid
*/
+
+// patterns for use in email detection and validation
+// NOTE: there is an unquoted '/' in RFC2822_ATEXT, it must remain unquoted to be used in the parser
+// the pattern uses non-capturing groups as captured groups aren't allowed in the parser
+// select pattern delimiters with care!
+if (!defined('RFC2822_ATEXT')) define('RFC2822_ATEXT',"0-9A-Za-z!#$%&'*+/=?^_`{|}~-");
+if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '['.RFC2822_ATEXT.']+(?:\.['.RFC2822_ATEXT.']+)*@(?:[0-9A-Za-z][0-9A-Za-z-]*\.)+[A-Za-z]{2,4}');
+
function mail_isvalid($email){
- return eregi("^[0-9a-z]([+-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$", $email);
+ return preg_match('<^'.PREG_PATTERN_VALID_EMAIL.'$>', $email);
}
/**