I want to add validation to the node title field. When the user enters the character X and submits the form they should get a message saying "you are not allowed to enter special character X".

4 Answers 4


You can setup field/property validations with the module Field validation.

Here's the documentation on how to add validation to properties (with the Field validation module), as the title isn't a field in Drupal 7.

  • in this they cannot show node title field in selecting list Commented Aug 15, 2014 at 7:36
  • I dont understand? Do you want the node title to be a select with a dropdown? Commented Aug 15, 2014 at 7:38
  • yes i want exactly Commented Aug 15, 2014 at 7:41
  • 1
    That seems like a complete different question to me, maybe update your question or write a new one. You asked about validating the node title field which is a completely different question :) Commented Aug 15, 2014 at 7:43
  • i am just add some validation or any other way user cannot enter special character in node title or they cannot save the node content Commented Aug 15, 2014 at 7:46

Check these module Node Title Validation

These is very light weight module, and helps to validate node titles with min/max characters, Blacklist characters/words and unique node titles.


You can implement hook_node_validate() and check the special character in node title.

function MYMODULE_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) !== 0){
   form_set_error('title', 'Special character are not allowed in form title.')


function MYMODULE_node_validate($node, $form, $form_state){
  // special character list, Add more special character if you want, escape the character if required.
  $special_character_list = '\'^£$%&*()}{@#~?><>,|=_+¬\-\[\]';
  if(preg_match('/[' . $special_character_list . ']/', $node->title) !== 0){
    form_set_error('title', t("Special characters !special_character_list are not allowed in title.", array('!special_character_list' => $special_character_list)));
  • Shouldn't that be t() rather than format_string() in the updated version?
    – Andy
    Commented Aug 15, 2014 at 8:40
  • Yes you are right. It should be t() if we want to allow translation. t() calls format_string() internally. Commented Aug 15, 2014 at 9:04
  • thank you @MutantMahesh for this if i am apply on webform title field then what i do Commented Aug 15, 2014 at 9:06
  • @user25762 It will work for webform edit form, because webform is also a node. If you want to use this for webform textfield then you can check this in hook_form_alter or use drupal.org/project/webform_validation Commented Aug 15, 2014 at 9:10
  • not working with module Commented Aug 15, 2014 at 11:15

I had the same problem, field validation module work correctly for another field but when I want to validate title I can't validate it and finally find the Title module ,

After enabling the module as usual, visit the Manage fields page of the content type, taxonomy vocabulary or "comment type" which you wish to replace fields of and click the replace link. That's all.

after installing this module go to your field management and see "Replace" beside title , with this feature, it convert drupal default title and after converting you can work with field title like another fields. I hope this help you and future guys that have the same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.