# How to set character length (maxlength) for input box/text box

**URL:** https://discourse.processing.org/t/how-to-set-character-length-maxlength-for-input-box-text-box/21663
**Category:** Beginners
**Created:** [June 7, 2020, 4:55pm UTC](https://discourse.processing.org/t/how-to-set-character-length-maxlength-for-input-box-text-box/21663 "2020-06-07T16:55:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![chrisdean](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@chrisdean](https://discourse.processing.org/u/chrisdean)
#### Post date: [June 7, 2020, 4:55pm UTC](https://discourse.processing.org/t/how-to-set-character-length-maxlength-for-input-box-text-box/21663/1 "2020-06-07T16:55:35Z")

</div>

Hi all,

The subject line says it all really. I have created an input box to enter text, but I need to set the maximum amount of characters that someone can type into it, ie. for a name.

```auto

input = createInput();
input.position(20,20);
input.style.... etc. etc.

```

But how do I set the maxlength?

Many thanks.

Chris.

```auto

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [June 7, 2020, 5:13pm UTC](https://discourse.processing.org/t/how-to-set-character-length-maxlength-for-input-box-text-box/21663/2 "2020-06-07T17:13:01Z")

</div>

You may try out method **attribute()** in order to add _maxlength_:

- [p5js.org/reference/#/p5.Element/attribute](http://p5js.org/reference/#/p5.Element/attribute)
- [Developer.Mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefmaxlength](http://Developer.Mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefmaxlength)

`input = createInput().attribute('maxlength', maxChars);`

---

<div class="post-metadata">

### Author: ![chrisdean](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@chrisdean](https://discourse.processing.org/u/chrisdean)
#### Post date: [June 7, 2020, 7:01pm UTC](https://discourse.processing.org/t/how-to-set-character-length-maxlength-for-input-box-text-box/21663/3 "2020-06-07T19:01:54Z")

</div>

Thank you very much for the fast reply, very kind.

This solution will be perfect. I was not aware of it.
