Specific character length on field and correction to Uppercase letters

Hey, i want to minimize field value to a 6 digits.
3 letters and 3 numbers
i don’t want any more characters to be typed in.
Also, once letters typed it, it must be changed to uppercase.
space does not count as a digit.

All this would likely be trivial if Axure supported regex (and someone were experienced with regex–not me.) Alas, Axure does not support regex (regular expressions) but I thought it wouldn’t be too hard to use a "brute force" approach. I was wrong, as it was more complicated than I expected. My resulting solution works, but is not too efficient.

You can limit the number of characters accepted in a Text Field or Text Area widget by right-clicking the field widget and selecting Edit Max Length (also available in the INTERACTIONS pane under TEXT FIELD PROPERTIES (Show All)) and entering a value of 6.

However, your last requirement, "space does not count as a digit" would not work because an entered space is a character, so "abc123" is possible, but "abc 123" would not work with max length of 6. A workaround is to test the last character input and remove it if it is a space. This works if the end value of the input field should not contain spaces. If you want the ability to input and retain spaces, you could count the "non-whitespace" characters and manually stop input at 6 valid characters, or allow spaces but not handle them as digits or letters.

A simple way to handle this is to validate the field’s text value after "submit" (or "enter" or "lost focus") and show an error if more than 3 letters or more than 3 digits. You could also set up some cases to validate input "on the fly" as user enters characters, such that "abc" is normal, but then "abcd" would result in an error–or just removal of the fourth letter or fourth digit. Use the KEY UP event for the text field to handle input "on the fly" as each character is entered.

Again, you can convert the char values of the field’s text value either on "submit" or on the fly. The basic algorithm is [[Target.text.toUpperCase()]]

To handle up to 3 digits and up to 3 letters, I created two global variables, inputDigit and inputAlpha in order to keep count of each. I also added a global variable to keep track of the last character input–in order to handle backspaces (did user just delete a letter or a digit? --need to adjust the count accordingly)–and named it inputType.

Take a look at the interaction code for the text field in this file. It handles input on the fly with a series of cases for KEY UP and a "sub-function" to validate input by using the MOVED event each time a new character is entered.

text field validation 6 chars.rp (55.4 KB)

2 Likes