Title: Set Maximum Field Length
Last modified: October 26, 2017

---

# Set Maximum Field Length

 *  Resolved [317th](https://wordpress.org/support/users/317th/)
 * (@317th)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/set-maximum-field-length/)
 * I read a post a while back about potentially enabling the ability to set maximum
   field length. Has that feature been added or is it planned?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Jess Quig](https://wordpress.org/support/users/jquigam/)
 * (@jquigam)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/set-maximum-field-length/#post-9626839)
 * Hi 317th,
 * We don’t currently have any built in ability to limit the number of characters
   for a field, though this is on our feature request list (and I’ll add your vote
   to that, as well).
 * This can be done, though, with a little custom code:
 *     ```
       /**
        * Limit number of characters allowed for a field
        * Apply the class "wpf-char-limit" to the field to enable.
        *
        */
       function wpf_char_limit() {
       	?>
       	<script type="text/javascript">
       		jQuery(function($){
       			$('.wpf-char-limit').attr('maxlength',9); // Change number to character limit
       		});
       	</script>
       	<?php
       }
       add_action( 'wpforms_wp_footer', 'wpf_char_limit' );
       ```
   
 * In case it helps, we have [a tutorial with how to add custom code like this here](https://developers.wpforms.com/docs/how-to-add-custom-php-or-javascript-for-wpforms/).
 * Once you’ve added the code to your site, you’ll need to do a couple things:
 * 1) Adjust the number for the max character length (if you look in the code, it’s
   currently set to 9).
 * 2) Then, you’ll need to open the form builder and click on the field you want
   to apply this to. From that Field Options panel, you’ll need to open Advanced
   Options then add “wpf-char-limit” to the CSS Classes field. [Here’s a screenshot](http://cloud.supportally.com/0G3w2f3x2a1K)
   so you can see exactly how that should look.
 * With this approach, you can apply this same character limit to any WPForms field
   on your site.
 * I hope that helps! Please let me know if you have any questions 🙂
 *  [polychromatic](https://wordpress.org/support/users/polychromatic/)
 * (@polychromatic)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/set-maximum-field-length/#post-9786396)
 * Unfortunately, this solution didn’t work for me. Will this solution prevent additional
   text from being entered at the specified limit, or is it supposed to block the
   submission?
 * Please add another vote for this feature; it was essential when using Contact
   Form 7, and I’m really missing it since migrating to WPForms!
    -  This reply was modified 8 years, 4 months ago by [polychromatic](https://wordpress.org/support/users/polychromatic/).
    -  This reply was modified 8 years, 4 months ago by [polychromatic](https://wordpress.org/support/users/polychromatic/).
 *  [Jess Quig](https://wordpress.org/support/users/jquigam/)
 * (@jquigam)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/set-maximum-field-length/#post-9786707)
 * Hi polychromatic,
 * Certainly, I’ve added your vote to this feature request 🙂
 * In case it helps, we’ve recently published a tutorial for this in our developer
   docs: [https://developers.wpforms.com/docs/limit-number-of-characters-for-a-text-field/](https://developers.wpforms.com/docs/limit-number-of-characters-for-a-text-field/).
   The code is the same, but the details of its use are hopefully clearer there.
 * This code is meant to limit the number of characters that can be entered into
   a field (so if the user tries to type more than that limit, it just won’t work—
   no additional characters can be entered).
 * I hope that helps!
 *  [polychromatic](https://wordpress.org/support/users/polychromatic/)
 * (@polychromatic)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/set-maximum-field-length/#post-9786802)
 * Curious; I wonder why it doesn’t do that for me. I can keep typing away without
   any issue. Maybe I’ll try another route other than Code Snippets.
 * Thanks!
 *  [Jess Quig](https://wordpress.org/support/users/jquigam/)
 * (@jquigam)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/set-maximum-field-length/#post-9786937)
 * Hi polychromatic,
 * Sorry about that! Possibly there’s a conflict with some other JavaScript on your
   site.
 * If you’re interested in pursuing this further, [this guide from WPBeginner](http://www.wpbeginner.com/beginners-guide/beginners-guide-to-troubleshooting-wordpress-errors-step-by-step/)
   walks through how to track down code conflicts with other plugins or a site’s
   theme.
 * And if you do decide to pursue this and find a conflict source, please let us
   know — that way hopefully it may help others who find this thread and experience
   a similar issue.
 * Thanks! 🙂

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Set Maximum Field Length’ is closed to new replies.

 * ![](https://ps.w.org/wpforms-lite/assets/icon.svg?rev=3254748)
 * [WPForms - Easy Form Builder for WordPress - Contact Forms, Payment Forms, Surveys, & More](https://wordpress.org/plugins/wpforms-lite/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpforms-lite/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpforms-lite/)
 * [Active Topics](https://wordpress.org/support/plugin/wpforms-lite/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpforms-lite/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpforms-lite/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [Jess Quig](https://wordpress.org/support/users/jquigam/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/set-maximum-field-length/#post-9786937)
 * Status: resolved