Habari\FormValidators::validate_email PHP Метод

validate_email() публичный статический Метод

A validation function that returns an error if the value passed in is not a valid Email Address, as per RFC2822 and RFC2821.
public static validate_email ( string $text, FormControl $control, FormContainer $form, string $warning = null ) : array
$text string A string to test if it is a valid Email Address
$control FormControl The control that defines the value
$form FormContainer The container that holds the control
$warning string An optional error message
Результат array An empty array if the string is a valid Email Address, or an array with strings describing the errors
    public static function validate_email($text, $control, $form, $warning = null)
    {
        if (!empty($text)) {
            if (!preg_match("@^[a-z0-9!#\$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#\$%&'*+/=?^_`{|}~-]+)*\\@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\$@i", $text)) {
                $warning = empty($warning) ? _t('Value for %s must be a valid Email Address.', array($control->get_label())) : $warning;
                return array($warning);
            }
        }
        return array();
    }