Restrict text input

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.

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

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

Very nice!! Very easy too…

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.

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 )
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 )
P.S. Carriage return would be hexadecimal 0D
Best regards

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

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
	  event.source.regExOK = False
1 Like

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

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. :slight_smile:

1 Like

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

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

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.