# How to check a text field length

**URL:** <https://forum.inductiveautomation.com/t/how-to-check-a-text-field-length/104506>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [April 1, 2025, 11:46am UTC](https://forum.inductiveautomation.com/t/how-to-check-a-text-field-length/104506 "2025-04-01T11:46:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dario.cappuccio](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@dario.cappuccio](https://forum.inductiveautomation.com/u/dario.cappuccio)\
**Post date:** [April 1, 2025, 11:46am UTC](https://forum.inductiveautomation.com/t/how-to-check-a-text-field-length/104506/1 "2025-04-01T11:46:55Z")

</div>

Hi,  
I've a text field binding with a tag. The user can insert the text and I want to limit the number of char to 10.  
How can I do it? Where can I insert the code? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 1, 2025, 12:07pm UTC](https://forum.inductiveautomation.com/t/how-to-check-a-text-field-length/104506/2 "2025-04-01T12:07:53Z")

</div>

Set up your props by unchecking defer updates and rejectUpdatesWhileFocused.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/a/9a1f0a16682e97e099a922c871b4a62865b9ca96.png)

Then in the `onKeyPress` event handler add this script. (There may be a better way to handle this, but it works.)

```python
	if len(self.props.text) > 10:
		self.props.text = self.props.text[:10]

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/c/6cb81e71800876bfe12c9227e26d021f81979b0d.png)

---

<div class="post-metadata">

**Author:** ![dario.cappuccio](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@dario.cappuccio](https://forum.inductiveautomation.com/u/dario.cappuccio)\
**Post date:** [April 1, 2025, 12:24pm UTC](https://forum.inductiveautomation.com/t/how-to-check-a-text-field-length/104506/3 "2025-04-01T12:24:54Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/c/4cba6fe83b36bc9b93245a3ed210a90f166735c5.png)  
I still have the error : error writing to myTag . Bad Out of range.

---

<div class="post-metadata">

**Author:** ![Matej\_Medvecky](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@Matej\_Medvecky](https://forum.inductiveautomation.com/u/Matej_Medvecky)\
**Post date:** [April 1, 2025, 12:42pm UTC](https://forum.inductiveautomation.com/t/how-to-check-a-text-field-length/104506/4 "2025-04-01T12:42:17Z")

</div>

What about expression binding with `left(value,10)` ?

> **[left | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/string/left)**
>
> Returns count characters from the left side of string, where count and string are the arguments to the function.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 1, 2025, 12:54pm UTC](https://forum.inductiveautomation.com/t/how-to-check-a-text-field-length/104506/5 "2025-04-01T12:54:34Z")

</div>

You can't bind the value to itself, that is an infinite loop

> [@dario.cappuccio](#):
>
> I still have the error : error writing to myTag . Bad Out of range.

Is the tag bound to the text input value, or are you writing the value to the tag with a script? Share more info on your current setup.

---

<div class="post-metadata">

**Author:** ![dario.cappuccio](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@dario.cappuccio](https://forum.inductiveautomation.com/u/dario.cappuccio)\
**Post date:** [April 1, 2025, 2:12pm UTC](https://forum.inductiveautomation.com/t/how-to-check-a-text-field-length/104506/6 "2025-04-01T14:12:24Z")

</div>

thank you for your help, I've resolve using your script and uncheck the bidirectional on the bindign property
