# How to set the attribute "maxlength" to a textinput

**URL:** <https://discourse.nodered.org/t/how-to-set-the-attribute-maxlength-to-a-textinput/20758>\
**Category:** Dashboard\
**Created:** [23 January 2020 06:54 UTC](https://discourse.nodered.org/t/how-to-set-the-attribute-maxlength-to-a-textinput/20758 "2020-01-23T06:54:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zappogb1](https://avatars.discourse-cdn.com/v4/letter/z/dfb087/32.png) [@zappogb1](https://discourse.nodered.org/u/zappogb1)\
**Post date:** [23 January 2020 06:54 UTC](https://discourse.nodered.org/t/how-to-set-the-attribute-maxlength-to-a-textinput/20758/1 "2020-01-23T06:54:46Z")

</div>

i want to limit the input size in one text input field  
Is this possible with the ui\_template or do i have to use st else?

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/c/cce0e49a91dff8626d8ae7b742432a7e67405b6a.png)  
The two fields "nickname pick-up" and "ID (Card)" have to be limited.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [23 January 2020 09:13 UTC](https://discourse.nodered.org/t/how-to-set-the-attribute-maxlength-to-a-textinput/20758/2 "2020-01-23T09:13:48Z")

</div>

Hi - no you can't set the max width - sorry. You would have to recreate the whole form with a template instead.

---

<div class="post-metadata">

**Author:** ![zappogb1](https://avatars.discourse-cdn.com/v4/letter/z/dfb087/32.png) [@zappogb1](https://discourse.nodered.org/u/zappogb1)\
**Post date:** [31 January 2020 11:44 UTC](https://discourse.nodered.org/t/how-to-set-the-attribute-maxlength-to-a-textinput/20758/3 "2020-01-31T11:44:34Z")

</div>

is there any other way  
for example: changing the color if the input number of chars is higher then the maximum length?  
or sth else?

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [2 February 2020 00:09 UTC](https://discourse.nodered.org/t/how-to-set-the-attribute-maxlength-to-a-textinput/20758/4 "2020-02-02T00:09:57Z")

</div>

One thing you can do easily is wait for the user to submit the input and then check it for validity. If the strings are too long, you don't pass the input along but instead prompt the user for shorter ones. This flow is a crude example:

```auto
[{"id":"4c76b829.644aa","type":"ui_form","z":"21415eb.4206da2","name":"","label":"","group":"58239138.4af19","order":3,"width":0,"height":0,"options":[{"label":"5 character maximum","value":"max5","type":"text","required":false,"rows":null},{"label":"7 character maximum","value":"max7","type":"text","required":false,"rows":null}],"formValue":{"max5":"","max7":""},"payload":"","submit":"submit","cancel":"cancel","topic":"","x":410,"y":140,"wires":[["d7ac73a1.858a78"]]},{"id":"c283b516.43f68","type":"debug","z":"21415eb.4206da2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":80,"wires":[]},{"id":"d7ac73a1.858a78","type":"function","z":"21415eb.4206da2","name":"verify","func":"let msg2 = {}\nlet len1 = msg.payload.max5.length\nlet len2 = msg.payload.max7.length\nif (len1 < 5 & len2 < 7){\n node.send([msg,null])\n} \nif (len1 > 5){\n msg2.payload = {max5:\"input too long\"}\n node.send([null,msg2])\n}\nif (len2 > 7){\n msg2.payload = {max7:\"input too long\"}\n node.send([null,msg2])\n}\n","outputs":2,"noerr":0,"x":530,"y":80,"wires":[["c283b516.43f68"],["4c76b829.644aa"]]},{"id":"58239138.4af19","type":"ui_group","name":"Group 2","tab":"1b0057e0.037f48","order":2,"disp":true,"width":6},{"id":"1b0057e0.037f48","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

In any case, it's always a good idea to check user input for validity and sanity.
