Drupal

Drupal 7 node title show error when enter special characters

If you don’t want to allow special character in node title of Drupal node then you can do this with one simple hook hook_node_validate. This hook will be called when you create a new node or you update any existing hook.

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

One thought on “Drupal 7 node title show error when enter special characters

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s