How to Change the Limit Character Validation Text

Introduction

Would you like to change the Limit Character 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.

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.

Adding the snippet

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.

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   
    
    // 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}.', '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 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   
    
    // 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}.', 'plugin-domain' );
	return $strings;
}

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