How to Change the Limit Character Validation Text

Curious about altering the character limit text shown beneath your form fields, especially when employing the Character Limit on Single Line Text or Paragraph Text form fields?

By default, you’ll notice a message below the form field indicating the current character count out of the maximum limit, such as 0 out of 50 max characters or 0 out of 50 max words, depending on your form settings. You can personalize this message to include the count of remaining characters. This adjustment is easily accomplished with a simple PHP snippet. In this tutorial, we’ll walk through how to utilize PHP to alter this message.

Creating the form

First, we’ll need to create our form and add our form fields.

If you need any help in creating your form, please check out this documentation.

add your fields to your new form

We’ve added a Paragraph Text form field to hold our engraved message.

Setting the character limit

Next, select the Paragraph Text you added and click on the Advanced tab to enable the Limit Length option and set the limit to 100 and select Character from the dropdown.

enable the Limit Length option on the Advanced tab

For further information on the Limit Length option, please review this documentation.

Changing the limit character validation text

Now it’s time to add the snippet to your site.

If you’re not sure how or where to add snippets to your site, please check out this tutorial.

/**
 * Change the text for the character limit.
 *
 * @link https://wpforms.com/developers/how-to-change-the-limit-character-validation-text/
 */

function wpf_dev_frontend_strings( $strings ) {
	
    // val_limit_words when using words
    // val_limit_characters when using characters   
    
    // Change the message that will appear to your visitors after the = sign below
    $strings[ 'val_limit_characters' ] = __( 'You have used {count} characters out of allotted {limit}. You have {remaining} remaining.', 'plugin-domain' );

	return $strings;
}

add_filter( 'wpforms_frontend_strings' , 'wpf_dev_frontend_strings', 10, 1 );

with this snippet users can see how many characters they have left from the character limit

And that’s it! You’ve successfully changed the limit character text that shows under the form field when using the character or word limit. Would you also like to also have a minimum number of characters set for your form field? Take a look at our tutorial on How to Set a Minimum Number of Characters on a Text Form Field.

Reference Filter

wpforms_frontend_strings

FAQ

Q: How would I change the text when using Word limit and not Character limit?

A: To change the text for the Word limit, please use the following code snippet:

/**
 * Change the text for the character limit.
 *
 * @link https://wpforms.com/developers/how-to-change-the-limit-character-validation-text/
 */

function wpf_dev_frontend_strings( $strings ) {
	
    // val_limit_words when using words
    // val_limit_characters when using characters   
    
    // Change the message that will appear to your visitors after the = sign below
    $strings[ 'val_limit_words' ] = __( 'You have used {count} words out of allotted {limit}. You have {remaining} remaining.', 'plugin-domain' );
	return $strings;
}

add_filter( 'wpforms_frontend_strings' , 'wpf_dev_frontend_strings', 10, 1 );

Q: Can I change this for both words and characters in one function?

A: Absolutely! You can change this text for both words and characters in one single function by using this snippet.

/**
 * Change the text for the character and word limit.
 *
 * @link https://wpforms.com/developers/how-to-change-the-limit-character-validation-text/
 */
  
function wpf_dev_frontend_strings( $strings ) {
      
    // val_limit_words when using words
    // val_limit_characters when using characters   
      
    // Change the message that will appear to your visitors after the = sign below
    $strings[ 'val_limit_words' ] = __( 'You have used {count} words out of allotted {limit}. You have {remaining} remaining.', 'plugin-domain' );
    $strings[ 'val_limit_characters' ] = __( 'You have used {count} characters out of allotted {limit}. You have {remaining} remaining.', 'plugin-domain' );
    return $strings;
}
  
add_filter( 'wpforms_frontend_strings' , 'wpf_dev_frontend_strings', 10, 1 );

Q: Can I remove the text that shows completely?

A: You can, of course, remove this message. But keep in mind, if you’re visitors are typing and then suddenly can’t type anymore due to the limit, this could cause confusion when completing the form. We recommend leaving some sort of message explaining the limit. However, if you’d still like to remove the message that appears completely, use this snippet instead.

/**
 * Remove the text for the character and word limit.
 *
 * @link https://wpforms.com/developers/how-to-change-the-limit-character-validation-text/
 */
 
function wpf_dev_frontend_strings( $strings ) {
     
    // val_limit_words when using words
    // val_limit_characters when using characters   
     
    // Change the message that will appear to your visitors after the = sign below
    $strings[ 'val_limit_words' ] = '';
    $strings[ 'val_limit_characters' ] = '';
    return $strings;
}
 
add_filter( 'wpforms_frontend_strings' , 'wpf_dev_frontend_strings', 10, 1 );