Method to test the email address and optionally check for uniqueness.
{
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
if (!$required && empty($value))
{
return true;
}
$tld = ((string) $element['tld'] == 'tld' || (string) $element['tld'] == 'required');
if ($tld)
{
$this->regex = '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]{2,})$';
}
$multiple = ((string) $element['multiple'] == 'true' || (string) $element['multiple'] == 'multiple');
if (!$multiple)
{
if (!parent::test($element, $value, $group, $input, $form))
{
return false;
}
}
else
{
$values = explode(',', $value);
foreach ($values as $value)
{
if (!parent::test($element, $value, $group, $input, $form))
{
return false;
}
}
}
$unique = ((string) $element['unique'] == 'true' || (string) $element['unique'] == 'unique');
if ($unique && !$multiple)
{
$query = $db->getQuery(true);
$query->select('COUNT(*)')
->from('#__users')
->where('email = ' . $db->quote($value));
$query->where($db->quoteName('id') . ' <> ' . (int) $userId);
$db->setQuery($query);
$duplicate = (bool) $db->loadResult();
if ($duplicate)
{
return false;
}
}
return true;
}