A
A
Artem Prokhorov2021-08-02 10:59:32
PHP
Artem Prokhorov, 2021-08-02 10:59:32

How to prevent a user from writing contact information in a comment?

I mean some kind of ready-made solution / extension for puff or yii, so as not to write regular expressions. Block the spelling of the phone 8999... 8-999... 8 9 9 9, etc., cart, mail, etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Danchenko, 2021-08-02
@kotcich

function removeEmailAndPhoneFromString($string) {
    // remove email
    $string = preg_replace('/([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/','',$string);

    // remove phone
    $string = preg_replace('/([0-9]+[\- ]?[0-9]+)/','',$string);

    return $string;
}

// Привет, это я. Мой номер +, напиши мне на 
echo removeEmailAndPhoneFromString('Привет, это я. Мой номер +375442381342, напиши мне на [email protected]');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question