Limit Phone Number Field Length in WordPress Forms
This article will guide you on how to limit the Phone Number field length in your FireBox WordPress form.
Enable PHP Scripts
This guide requires that PHP Scripts be enabled to perform these validations. To enable PHP Scripts, go to FireBox > Settings > Advanced > enable PHP Scripts.

How to Limit the Phone Number Field by Characters
To limit a phone number form field and require up to X characters, edit your FireBox campaign, go to PHP Scripts section > Form Process, and add:
// Enter your phone number field name
$phone_number_field_name = 'phonenumber';
// Enter the maximum number of characters allowed in the phone number field
$phone_number_characters_limit = 10;
// Enter the error message to be displayed if the phone number exceeds the limit
$phone_number_error_message = 'The phone number field can contain up to 10 characters';
// Do not edit below
if (isset($values[$phone_number_field_name]) && is_array($values[$phone_number_field_name]) && isset($values[$phone_number_field_name]['value']) && strlen($values[$phone_number_field_name]['value']) > $phone_number_characters_limit) {
throw new \Exception($phone_number_error_message);
}
You must set up the following:
- Set your phone number field name in $phone_number_field_name
- Set the max characters allowed in $phone_number_characters_limit
- Set the error message that will appear when the criteria are not met in $phone_number_error_message
Other Guides
Was this helpful?