How to Change the Limit Character Validation Text

Overview

Would you like to change the text that appears under the form field when using the Character Limit on Single Line Text or Paragraph Text form fields? By default, you will see a message under the form field that will state 0 out of 50 max characters or 0 out of 50 max words (depending on your form settings). You can easily change this text with a small PHP snippet. In this tutorial, we’ll give you the PHP needed to change this text.

Setup

First, you’ll need to set up your form using the character (or word) limit. For help with this, please view this tutorial.

Next, you’ll need to copy this code to your site.

/**
 * 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   
    
    $strings['val_limit_characters'] = 'You have used {count} characters out of allotted {limit}.';
	return $strings;
}
add_filter( 'wpforms_frontend_strings' , 'wpf_dev_frontend_strings', 10, 1 );

Just remember to change the text inside 'You have used {count} characters out of allotted {limit}.'; to match what you want to show on your site.

And that’s it! You’ve successfully changed the 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.

Filter Reference: 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   
    
    $strings['val_limit_words'] = 'You have used {count} words out of allotted {limit}.';
	return $strings;
}
add_filter( 'wpforms_frontend_strings' , 'wpf_dev_frontend_strings', 10, 1 );