8 – Special characters are not allowed in the title when creating content

It's a recommendation that they made me. And I want to add to my contents. To avoid mistakes in the creation of new content.

I tried the following module but with very poor results. I configured the module correctly for some reason it did not work.
Save correct, but when I tried it, it does not work.

Also, I have tested the module. Field validation. Adding a new validation to the field title but none worked.

Also, I have created a custom module with a hook. without good results

function custom_node_validate ($ node, $ form, $ form_state)
{
// list of special characters, add more special characters if you want.
$ special_character_list = & # 39;  & # 39; ^ £ $% & * ()} {@ # ~?>, | = _ + ¬  - []& # 39 ;;
if (preg_match (& # 39; /[' . $special_character_list . ']/ & # 39 ;, $ node-> title, $ matches)! == 0) {
form_set_error (& # 39; title & # 39 ;, format_string ("Special characters! special_character_list are not allowed in the title.", array (& # 39 ;! special_character_list & # 39; => $ special_character_list)));
}
}

What is the recommendation that you give me?

I use for my environment:

  • Centos 7
  • Drupal 8.6.1
  • Apache 2.4
  • Php 7

Thanks for helping me people