# Limit Characters in a Textbox when Typing

**URL:** <https://forum.inductiveautomation.com/t/limit-characters-in-a-textbox-when-typing/29372>\
**Category:** Ignition\
**Tags:** ignition79, vision\
**Created:** [October 24, 2019, 6:17pm UTC](https://forum.inductiveautomation.com/t/limit-characters-in-a-textbox-when-typing/29372 "2019-10-24T18:17:30Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [October 24, 2019, 7:04pm UTC](https://forum.inductiveautomation.com/t/limit-characters-in-a-textbox-when-typing/29372/2 "2019-10-24T19:04:39Z")

</div>

Add an integer custom property to the field to hold your length limit (doesn’t work with the built-in). I used `altMax` for the following:

```auto
if event.propertyName == 'text':
	tf = event.source
	print event
	if tf.focusOwner and tf.altMax > 1:
		if len(event.newValue) >= tf.altMax:
			tf.select(tf.altMax-1, len(event.newValue))
			if len(event.newValue) > tf.altMax:
				tf.replaceSelection(event.newValue[tf.altMax-1])

```

Turn off defer updates and reject updates.

---

_[View the full topic](https://forum.inductiveautomation.com/t/limit-characters-in-a-textbox-when-typing/29372)._
