When creating an HTML form, it’s possible to add a maxlength attribute to any input box.
Since WPForms generates all field HTML for you, you can instead add the maxlength attribute using jQuery.
Adding this code will apply a maximum value of 40 to any Single Line Text form field or Paragraph Text form fields on your form using a CSS class named
To use this snippet, please follow the steps below.
2) Adding the CSS class
To add this class to a field, you’ll need to open the form builder, click the field to open its Field Options panel, and open the Advanced Options section.
In the CSS Classes just add the
Since this code will simply enforce a character limit, it’s also a good idea to let your users know about this limit within the field description.
For shorter character limits, or other format requirements, please consider using a custom input mask instead of the code below.
Action Reference: wpforms_wp_footer_end