IF exception?

Hi all, if you were trying to block all email addresses from being posted, except for ones that go to a certain domain, how would you do it please? This is what I’ve managed so far:

if ($user->data['user_posts'] < 100000) {
    if (preg_match('/(@|\(at\))/i', request_var('message', '', true))) {
        $error[] = $user->lang['NO_EMAILS'];
    }
}

The helps always appreciated.

How do you define “domain”? At least it’s the part after the @-sign, but that includes (multiple) subdomains and the TLD as well.

Sorry Chorn, I see I should have been clearer. So it would not allow any email addresses as per the existing code above, except if it was going to any email address at @testdomain.com

then you can just explode() for the @-sign and use the second array item from this.

Thanks Chorn, that’s appreciated, how would that complete code look like?

Why don’t you try something yourself? Here’s the manual:

https://www.php.net/manual/en/function.explode.php

Danger, Will Robinson.

Not everything with an @ sign is an email, is it @chorn ?

1 Like

no no, i may have mentioned validating the syntax for an emailadress first - but at least i don’t know the context this info will be processed further or if some pre-check is previously made anyway.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.