# Ignition perspective Limit number of characters allowed in input text field

**URL:** <https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937>\
**Category:** Ignition\
**Tags:** ignition80, perspective\
**Created:** [August 20, 2020, 9:55am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937 "2020-08-20T09:55:27Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alok.Vijayakumar](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@Alok.Vijayakumar](https://forum.inductiveautomation.com/u/Alok.Vijayakumar)\
**Post date:** [August 20, 2020, 9:55am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/1 "2020-08-20T09:55:27Z")

</div>

how to limit number of characters allowed in input text field and text area in ignition perspective

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 20, 2020, 2:14pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/2 "2020-08-20T14:14:25Z")

</div>

This might help.

> [@Limit Characters in a Textbox when Typing](http://forum.inductiveautomation.com/t/limit-characters-in-a-textbox-when-typing/29372):
>
> I simply want to set a maximum length on a textbox so that when the user gets to that point, they cannot type any more. Evidently, the Maximum Characters property doesn’t actually prevent someone from continuing to type (which is misleading in the documentation). I tried to capture keystrokes and keep count and remove the last character if they’ve exceeded the limit, but then I have to reset focus to the end of the typed characters because the focus resets when I update the field. And if I turn…

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 20, 2020, 2:25pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/3 "2020-08-20T14:25:48Z")

</div>

This script is modified from what @pturmel wrote in the linked thread.

```auto
	tf = self
	if tf.custom.altMax > 1:
		if len(currentValue.value) > tf.custom.altMax:
			tf.props.text = tf.props.text[:tf.custom.altMax]

```

1. Create the custom property altMax
2. Turn off deferUpdates
3. Turn off rejectUpdatesWhileFocused
4. Put this in a property change script on the text property of text property on your text field.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [August 20, 2020, 4:12pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/4 "2020-08-20T16:12:55Z")

</div>

That can even be simplified a bit. The full ChangeScript can just be one line:

```auto
self.props.text = self.props.text[:self.custom.altMax]

```

There’s no need for a length check.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 20, 2020, 4:40pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/5 "2020-08-20T16:40:38Z")

</div>

TIL. I assumed slicing would throw an IndexOutOfBoundsException if self.custom.altMax was too big. Thanks for the simplification.

---

<div class="post-metadata">

**Author:** ![Alok.Vijayakumar](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@Alok.Vijayakumar](https://forum.inductiveautomation.com/u/Alok.Vijayakumar)\
**Post date:** [August 21, 2020, 6:53am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/6 "2020-08-21T06:53:17Z")

</div>

Thanks the simple solution. It work well

---

<div class="post-metadata">

**Author:** ![aliobaidi](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@aliobaidi](https://forum.inductiveautomation.com/u/aliobaidi)\
**Post date:** [May 23, 2021, 2:31pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/8 "2021-05-23T14:31:09Z")

</div>

can you elaborate on how to limit my text box input to 17 character I am not sure where to find this on the manual for more explanation I would really appreciate it. FYI my tag is a string character

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 24, 2021, 7:28pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/9 "2021-05-24T19:28:38Z")

</div>

To follow the example that @zacht posted.

create a custom property on the component named altMax  
set `deferUpdates` and `rejectUpdatesWhileFocused` to false

Righ click the text property, and then select `Add Change Script...`

Insert the script as @cmallonee posted (be sure to indent it correctly), click okay and you’re done.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 30, 2022, 2:16pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/10 "2022-03-30T14:16:16Z")

</div>

I get a ‘NoneType’ object is unsubscriptable

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 30, 2022, 2:19pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/11 "2022-03-30T14:19:44Z")

</div>

Going to need more information to help. What does your code look like?

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 30, 2022, 2:21pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/12 "2022-03-30T14:21:35Z")

</div>

it had a binding that was messing it up

---

<div class="post-metadata">

**Author:** ![AGOSTINO\_SCLAUZERO](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@AGOSTINO\_SCLAUZERO](https://forum.inductiveautomation.com/u/AGOSTINO_SCLAUZERO)\
**Post date:** [February 17, 2025, 7:26am UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/13 "2025-02-17T07:26:48Z")

</div>

This solution works, but it relies on turning off deferred updates. I have a database form that saves each field as it is entered, and in this case I really need deferred updates to avoid sending every single keystroke to the database. It would be really useful to have access to the maxlength html property of the input!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 17, 2025, 1:13pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-limit-number-of-characters-allowed-in-input-text-field/37937/14 "2025-02-17T13:13:20Z")

</div>

> [@AGOSTINO\_SCLAUZERO](#):
>
> database form that saves each field as it is entered

I would recommend changing that. It is too easy to screw up your database. Consider arranging your GUI to highlight fields that are now different from the DB, and using a button to save them all together.
