Validating Name or Last Name
Last updated on
30 April 2025
You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules
This script basically prevents numbers from being used in a field (or other non-alphabetic characters). This validation does not ensure name is mandatory, it should be ensured by field settings.
$name = $form_values['submitted_tree']['name'];
if (strlen(trim($name)) > 0 && !ereg('^[a-z A-Z\'\-]+$', $name)) {
form_set_error('submitted][name', t('Your name contains invalid characters. Only letters are allowed!'));
}
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion