Limit text field to specific length In my custom content type, I want restricted the length of text entered in a text field. I want to check whether a user entered e.g. thousands of words. For this I tried this one but unable to achieve.

$my_field = field_get_items('node',node_load($nid, NULL, TRUE), 'my_field');
$my_field = substr($my_field,0,100).'...';
print $my_field[0]['value'];


Is there any way to do this in drupal 7 context?
If you're really trying to restrict the character count at the point of entry you need to set the field in your form to have a #maxlength in your form definition.