Formatted Text Field pattern

Hi, I need help, I’m having difficult to set a Reg Ex Pattern in a formated text field.
The string have to be this way:
numbers(one digit to 3 digits variable) + one letter (A-I)

Example:
10A
123B
33F
1A

Additional, if is posible I have to accept blank string too.

^(?:\d{1,3}[A-I])?$

Assert position at the beginning of the line.
Open a group:

  • Accept between 1 and 3 digits (0-9)
  • Accept exactly one uppercase letter between A and I

Close the group.
Make the group optional (this allows an empty string to pass).
Assert position at the end of the line.

Might require some minor adjustments to work with the formatted text field.

Thanks for the help, I appreciate it, it works great!

In case you really want to get into regular expressions, I’ve always found it easiest to read them as nondeterministic finite automata.

That is, you read the string you want to check, character by character. For each character, you check if you can pass into a new state in the regex (go to a new regex part). Or perhaps you stay in the same part, or perhaps there are no options left and the string is refused.

After that, it’s just learning the syntax.

  • abc a regular string just recogises that
  • [abc] square brackets mean a set of possible characters
  • a* a star means it can be repeated 0 or more times
  • a+ a plus means it can be repeated 1 or more times
  • a? a question mark means it can be present 0 or 1 time
  • a{1,2} curly braces mean it can be repeated between min and max times
  • (abc)* round parenthesis group characters together
  • . a dot means any character
  • ^ the caret is the start of the string (or of the line, depending on the regex implementation)
  • $ the dollar sign is the end of the string (or of the line)
  • \. any special characters you want to use in a literal way need a backslash

Regexes become pretty powerful, but also pretty unreadable if you go too far with it… https://blog.codinghorror.com/regex-use-vs-regex-abuse/

3 Likes

Thanks for the info.