# Formatted Text Field pattern

**URL:** <https://forum.inductiveautomation.com/t/formatted-text-field-pattern/33257>\
**Category:** Ignition\
**Created:** [March 19, 2020, 9:53pm UTC](https://forum.inductiveautomation.com/t/formatted-text-field-pattern/33257 "2020-03-19T21:53:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoisesZV](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MoisesZV](https://forum.inductiveautomation.com/u/MoisesZV)\
**Post date:** [March 19, 2020, 9:53pm UTC](https://forum.inductiveautomation.com/t/formatted-text-field-pattern/33257/1 "2020-03-19T21:53:17Z")

</div>

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.

---

<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:** [March 19, 2020, 10:01pm UTC](https://forum.inductiveautomation.com/t/formatted-text-field-pattern/33257/2 "2020-03-19T22:01:48Z")

</div>

`^(?:\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.

> **[regex101: build, test, and debug regex](https://regex101.com/r/jFRsXp/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:** ![MoisesZV](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MoisesZV](https://forum.inductiveautomation.com/u/MoisesZV)\
**Post date:** [March 19, 2020, 10:28pm UTC](https://forum.inductiveautomation.com/t/formatted-text-field-pattern/33257/3 "2020-03-19T22:28:10Z")

</div>

> [@paul-griffith](#):
>
> ^(?:\d{1,3}[A-I])?$

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

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [March 20, 2020, 10:46am UTC](https://forum.inductiveautomation.com/t/formatted-text-field-pattern/33257/4 "2020-03-20T10:46:25Z")

</div>

In case you really want to get into regular expressions, I’ve always found it easiest to read them as [nondeterministic finite automata](https://en.wikipedia.org/wiki/Nondeterministic_finite_automaton).

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/](https://blog.codinghorror.com/regex-use-vs-regex-abuse/)

---

<div class="post-metadata">

**Author:** ![MoisesZV](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MoisesZV](https://forum.inductiveautomation.com/u/MoisesZV)\
**Post date:** [March 20, 2020, 11:09am UTC](https://forum.inductiveautomation.com/t/formatted-text-field-pattern/33257/5 "2020-03-20T11:09:39Z")

</div>

Thanks for the info.
