1

I' am getting the following characters on my website contact us form. How can I validate the message field so that such characters are not allowed.

Добрый день! Оказываем помощь в получении гражданам и Ñотрудникам фирм карточек метро в Ñеть немецких

This is the code am currently using

$message = sanitize_text_field($message);
$message = str_replace("`","", $message);
Devil Raily
  • 562
  • 1
  • 5
  • 15
  • 1
    I hope you are doing some kind of conditional validation. Here is an example `$message = 'This is my test message. I hope you are happy now!'; if( !preg_match('/^[a-zA-Z0-9\/\-.,;\'" ]+$/', $message)){$msg = 'The message field contains invalid characters.';}`. This will help you in telling the user that there are some strange characters in the message field. – Navneil Naicker Oct 23 '16 at 20:34
  • Thanks @NavneilNaicker It works great. – Devil Raily Oct 23 '16 at 20:36
  • Take a look here for examples using filter_var(). https://www.phpro.org/tutorials/Filtering-Data-with-PHP.html#12 – Kevin Waterson Oct 23 '16 at 20:52

0 Answers0