Source for file Email.php
Documentation is available at Email.php
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at
* http://formagic.weasle.de/licence.txt
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to licence@weasle.de so we can send you a copy immediately.
* @author Florian Sonnenburg
* @copyright Copyright (c) 2007 Florian Sonnenburg
* @license http://formagic.weasle.de/licence.txt New BSD License
* @revision $Revision: 17 $
require_once('Rule.php');
* Email rule checks if a valid email address is entered.
* The following arguments are supported:
* - (boolean)'checkDns': Performs DNS lookup
* If only one argument is passed instead of array, it is interpreted as 'checkDns'
* @author Florian Sonnenburg
* @copyright Copyright (c) 2007 Marc Schrader
* @version $Id: Email.php 17 2007-08-19 20:40:10Z meweasle $
private $_regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
* @param Formagic_Item $itemObj
public function check($item)
$value = $item->getValue();
if (!$value && !$item->hasRule('mandatory')) {
// Check value with Regex
// Check if DNS lookup is supported by PHP version and requested
$this->_args = array('checkDns' => (boolean) $this->_args);
if ( empty($this->_args['checkDns'])
if ( !checkdnsrr($tokens[1], 'MX')
&& !checkdnsrr($tokens[1], 'A')) {
|