Skip to content

Instantly share code, notes, and snippets.

@msankhala
Created August 15, 2014 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msankhala/e03e2071293e1073ea2b to your computer and use it in GitHub Desktop.
Save msankhala/e03e2071293e1073ea2b to your computer and use it in GitHub Desktop.
Show error on node title special character.
<?php
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) !== 0){
form_set_error('title', t("Special characters !special_character_list are not allowed in title.", array('!special_character_list' => $special_character_list)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment