# Limit Character Count for Form Field

**URL:** <https://community.hubspot.com/t/limit-character-count-for-form-field/11562>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [March 26, 2018, 6:23am UTC](https://community.hubspot.com/t/limit-character-count-for-form-field/11562 "2018-03-26T06:23:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulsPerkons](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/paulsperkons/32/35493_2.png) [@PaulsPerkons](https://community.hubspot.com/u/PaulsPerkons)\
**Post date:** [March 26, 2018, 6:23am UTC](https://community.hubspot.com/t/limit-character-count-for-form-field/11562/1 "2018-03-26T06:23:50Z")

</div>

Hi,

I have a form for which I have to make one of the fields allow a limited amount of characters to be input (minimum 2, maximum 12).

I found a solution mentioned in a different topic, which I tried to use, however, when I insert the actual code (the onformready), the form does not load anymore. Any possible way how I could approach this?

hbspt.forms.create({  
portalId: “XXX”,  
formId: “XXXXXXX”,  
css: “”,  
onFormReady: function($form) {  
$(“input[name=“vat\_number”]”).attr(‘maxlength’,‘12’);  
$(“input[name=“vat\_number”]”).attr(‘minlength’,‘2’);  
} ,  
});

---

<div class="post-metadata">

**Author:** ![Derek\_Gervais](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/derek_gervais/32/17429_2.png) [@Derek\_Gervais](https://community.hubspot.com/u/Derek_Gervais)\
**Post date:** [March 27, 2018, 5:54pm UTC](https://community.hubspot.com/t/limit-character-count-for-form-field/11562/2 "2018-03-27T17:54:35Z")

</div>

Hi @paulsperkons,

You’ll want to chain `.change()` to the end of each call, and also replace the left and right double quotes with standard double quotes (i.e. " )

![]() [developers.hubspot.com](https://developers.hubspot.com/docs/methods/forms/advanced_form_options)

### [How to customize the form embed code](https://developers.hubspot.com/docs/methods/forms/advanced_form_options)

This is a list of options that you can use if you just need to tweak a default hubspot form. If you need complete control over the styles and actions of your form, you will still want to use the Forms API.

---

<div class="post-metadata">

**Author:** ![PaulsPerkons](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/paulsperkons/32/35493_2.png) [@PaulsPerkons](https://community.hubspot.com/u/PaulsPerkons)\
**Post date:** [March 28, 2018, 7:53am UTC](https://community.hubspot.com/t/limit-character-count-for-form-field/11562/3 "2018-03-28T07:53:22Z")

</div>

Thank you. This fixed it.

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [August 3, 2018, 10:41pm UTC](https://community.hubspot.com/t/limit-character-count-for-form-field/11562/4 "2018-08-03T22:41:59Z")

</div>

Trying to set a character limit on a text field to 250 characters, but its not working. The form just submits no matter what without checking the character limitation. Any help with getting this working would be awesome.

Is the name= the id of the form field or something else?

hbspt.forms.create({  
portalId: “XXXXX”,  
formId: “XXXXXXXXXXXX”,  
css: “”,  
onFormReady: function($form) {  
$(‘input[name=“closed\_lost\_notes”]’).attr(‘minlength’,‘250’).change();  
$(‘input[name=“closed\_lost\_notes”]’).attr(‘maxlength’,‘2500’).change();  
},  
});

Also is there a way to show the character count and custom validation message if submitted before reaching the 250 character limit?

Thanks so much for any help!

---

<div class="post-metadata">

**Author:** ![Derek\_Gervais](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/derek_gervais/32/17429_2.png) [@Derek\_Gervais](https://community.hubspot.com/u/Derek_Gervais)\
**Post date:** [August 9, 2018, 4:54pm UTC](https://community.hubspot.com/t/limit-character-count-for-form-field/11562/5 "2018-08-09T16:54:57Z")

</div>

Hi [@Trevor\_Hatfield](https://community.hubspot.com/u/trevor_hatfield),

`name` is the input’s `name` attribute, which for HubSpot forms is the internal property name of the corresponding contact property. I’m not entirely sure why your code isn’t working; can you give me a link to the page you’re working on?

---

<div class="post-metadata">

**Author:** ![WTariq](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wtariq/32/75413_2.png) [@WTariq](https://community.hubspot.com/u/WTariq)\
**Post date:** [August 29, 2022, 2:29pm UTC](https://community.hubspot.com/t/limit-character-count-for-form-field/11562/6 "2022-08-29T14:29:45Z")

</div>

Hi All,  
I figured it out this way:

```lia-code-sample
hbspt.forms.create({
 portalId: "123456",
 formId: "abcd-efg-hijk=lmno",
 onFormReady: function($form) {
 $form.find('textarea[name="message"]').attr('maxlength','150');
 $form.find('input[name="what_are_you_planning"]').attr('maxlength','150');
 },
 });

```
