# Restrict text input

**URL:** <https://forum.inductiveautomation.com/t/restrict-text-input/27582>\
**Category:** Ignition\
**Created:** [August 19, 2019, 8:03pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582 "2019-08-19T20:03:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 19, 2019, 8:03pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582/1 "2019-08-19T20:03:08Z")

</div>

Curious the best way to go about this. I want to restrict a text input to a specific length, must be 6 characters (no more, no less), and each position is restricted to certain characters. For example, the first position can only have C,E,F,G,V. The 2nd-6th will have similar restrictions. I’m assuming I will use the key press event? Anyone have any additional tips or help?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 19, 2019, 8:09pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582/2 "2019-08-19T20:09:02Z")

</div>

Are you in Vision? Use a Formatted Text Field, with a regex pattern:

> **[regex101: build, test, and debug regex](https://regex101.com/r/GI10DR/1)**
>
> Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java. Features a regex quiz & library.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 19, 2019, 8:24pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582/3 "2019-08-19T20:24:35Z")

</div>

Yes, in vision. Thanks, I’ll take a look.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 19, 2019, 8:56pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582/4 "2019-08-19T20:56:48Z")

</div>

Very nice!! Very easy too…

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 25, 2019, 8:16pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582/5 "2019-08-25T20:16:40Z")

</div>

I ran into one issue I was hoping someone could help on. I was able to get the formatted text field to work with reg ex pattern. But, I still want to verify the operator has entered something. I can’t use committedValue because it always seems to have a value, if not from what they entered, then from the last time. I would rather use text, but for some reason it’s not exposed. So, how can one verify a value was entered?

Using 7.9.10, vision.

---

<div class="post-metadata">

**Author:** ![jlivingston](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jlivingston](https://forum.inductiveautomation.com/u/jlivingston)\
**Post date:** [August 26, 2019, 3:39pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582/6 "2019-08-26T15:39:58Z")

</div>

I think that you would need to that check their last input was a carriage return, the following may get you started, since most of this can be done with Python ( no colon equals no emoji )  
[https://docs.python.org/2/howto/unicode.html#unicode-literals-in-python-source-code](https://docs.python.org/2/howto/unicode.html#unicode-literals-in-python-source-code)  
I would otherwise suggest looking at the support policy section, then sending a message to support- yet this issue may or may not be considered their job- so here is the link ( no colon equals no emoji )  
[https://support.inductiveautomation.com](https://support.inductiveautomation.com)  
P.S. Carriage return would be hexadecimal 0D  
Best regards

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 28, 2019, 12:11pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582/7 "2019-08-28T12:11:07Z")

</div>

I did call support, we weren’t able to get it to work but, it was very simple to create the functionality using python:

```auto
import re

if event.propertyName == 'text':
	pattern = '^(?i)(c|e|f|g|v)(5|7|2|9|n|p)(0|c|x|s|g)(a|3|4|7|9|j|k|b|m|n|c|l|h|g|r|f|s|o|t|u|d|v|q|x|f|p)(0|1|2|3|g|b|c|d|j|k|l|m|n|r|4|t|f|5|6|7|8)(0|1|3|4|5|6|7|a|b|c|d|f|h|j|k|p|q|r|t|s|u|v|w|y|z)'
	string = event.source.text
	result = re.match(pattern, string)
	
	if result and len(string) == 6:
	  event.source.regExOK = True
	else:
	  event.source.regExOK = False

```

---

<div class="post-metadata">

**Author:** ![jlivingston](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jlivingston](https://forum.inductiveautomation.com/u/jlivingston)\
**Post date:** [August 28, 2019, 1:50pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582/8 "2019-08-28T13:50:05Z")

</div>

Thanks for the explanation. This may save me from having to ‘re-invent the wheel’ someday.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 28, 2019, 2:36pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582/9 "2019-08-28T14:36:00Z")

</div>

The only thing I would recommend is to put your group elements in alphanumeric order (0-9, a-z) like you did in the last group to make it easier to manage down the road, and avoid repeated elements. 🙂

---

<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:** [August 28, 2019, 2:46pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582/10 "2019-08-28T14:46:14Z")

</div>

I would avoid using the vertical bar operator. Use square brackets instead. Along with Jordan’s ordering advice. Like so:

```auto
pattern = '^(?i)[cefgv][2579np][0cgsx][3479a-df-hj-vx][0-8b-dfgj-nr][013-7a-dfhjkp-wyz]'

```

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 28, 2019, 2:57pm UTC](https://forum.inductiveautomation.com/t/restrict-text-input/27582/11 "2019-08-28T14:57:11Z")

</div>

Thanks guys, love the advice. I went strictly off of the customer’s document (in order), but I see your point(s). Looks cleaner for sure.
