0

I'm using JSN Uniform plugin for Joomla to receive emails, but it's not accepting the .company domain as a valid domain. It accepts the usual domains (com, net, org, info, biz,...), but domains like .company aren't accepted.

Now, I'm really not experienced in PHP, as I'm more into JavaScript, but according to my poor knowledge the solution to my problem could be in the form.php file so here is the part of a code.

PHP:

private function _fieldEmail($post, $fieldIdentifier, $fieldTitle, &$validationForm)
    {
        $postFieldIdentifier = isset($post[$fieldIdentifier]) ? $post[$fieldIdentifier] : '';
        $postFieldIdentifier = (get_magic_quotes_gpc() == true || get_magic_quotes_runtime() == true) ? stripslashes($postFieldIdentifier) : $postFieldIdentifier;
        $postEmail = $postFieldIdentifier;
        if ($postEmail)
        {
            $regex = '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,6})$/';
            if (!preg_match($regex, $postEmail))
            {
                $validationForm[$fieldIdentifier] = JText::sprintf('JSN_UNIFORM_FIELD_EMAIL', $fieldTitle);
            }
            else
            {
                return $postFieldIdentifier ? $postFieldIdentifier : "";
            }
        }
        else
        {
            return $postFieldIdentifier ? $postFieldIdentifier : "";
        }

    }

Could someone help me please with this?

Thanks.

EDIT: I have tried to change regex value from 2,6 to 2, but still no change.

Please see php fiddler here: http://viper-7.com/CqxAMZ

super11
  • 436
  • 7
  • 19
  • What a great illustration of the proverb *If you solve a problem with a regular expression, now you have two problems.* :-) Seriously, tell the "JSN Uniform" plugin developer to get with the times. – O. Jones Nov 06 '15 at 11:20
  • @OllieJones People complain on regex a lot for email validation, but the most in-depth and assertive expressions out there; cover edge cases that 99.99% of "real people" don't even introduce :P – Flosculus Nov 06 '15 at 11:33
  • I have edited the question. – super11 Nov 06 '15 at 12:21
  • The problem is not validating the email with a Regular Expression - it's validating the email with an oversimplified Regular Expression - it needs to cover all RFC 822 cases : http://www.w3.org/Protocols/rfc822/ http://ex-parrot.com/~pdw/Mail-RFC822-Address.html – CD001 Nov 06 '15 at 16:41
  • Okay, how do I solve this then? – super11 Nov 09 '15 at 08:10

3 Answers3

3

You should replace the regex like this:

$regex = '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,})$/';

to accept a domain of any size bigger than one. Now it is restricted to sizes between 2 and 6. More on the subject in http://www.regular-expressions.info/repeat.html

Amarnasan
  • 14,939
  • 5
  • 33
  • 37
1

Change {2,6} to {2,7} at the end.

That indicates the last part of the regex should contain between 2 and 7 characters ("company" exceeds the limit of 6).

fire
  • 21,383
  • 17
  • 79
  • 114
  • Read this: The longest allowable top-level-domain name is 63 characters. http://stackoverflow.com/questions/9238640/how-long-can-a-tld-possibly-be – O. Jones Nov 06 '15 at 11:22
1

Replace:

$regex = '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,6})$/';
if (!preg_match($regex, $postEmail))
{
    $validationForm[$fieldIdentifier] = JText::sprintf('JSN_UNIFORM_FIELD_EMAIL', $fieldTitle);
}

with:

if (!filter_var($postEmail, FILTER_VALIDATE_EMAIL)) {
    $validationForm[$fieldIdentifier] = JText::sprintf('JSN_UNIFORM_FIELD_EMAIL', $fieldTitle);
}

Email validate is more complicated that a one-line regex.

Flosculus
  • 6,880
  • 3
  • 18
  • 42