# RegEx with BarcodeInput component

**URL:** <https://forum.inductiveautomation.com/t/regex-with-barcodeinput-component/99387>\
**Category:** Ignition\
**Created:** [December 3, 2024, 10:05pm UTC](https://forum.inductiveautomation.com/t/regex-with-barcodeinput-component/99387 "2024-12-03T22:05:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [December 3, 2024, 10:05pm UTC](https://forum.inductiveautomation.com/t/regex-with-barcodeinput-component/99387/1 "2024-12-03T22:05:37Z")

</div>

I'm using the barcodeInput component with a Zebra Android scanner device. I want it to be able to take almost any input, so I made the RegEx

> (.{3,26})$

When I do this, it sends the barcode in accumulating chunks. For example, if I scan TC84309463, I get TC8 first, then I get the whole barcode, perhaps because my minimum size is 3? I append an enter onto the end of the barcode, and when I see an Enter in the data, I know that the input is a full barcode and process it from there.

Is that how it is supposed to work? Perhaps my regex isn't quite correct? Any help appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 3, 2024, 10:16pm UTC](https://forum.inductiveautomation.com/t/regex-with-barcodeinput-component/99387/2 "2024-12-03T22:16:21Z")

</div>

> [@ken.maze](#):
>
> (.{3,26})$  
> TC84309463

I tested your data in [https://regex101.com/](https://regex101.com/) and it works as you want.  
I was going to suggest `\r` or `\n` or `\r\n` before the `$` but it doesn't seem to be needed.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 3, 2024, 10:17pm UTC](https://forum.inductiveautomation.com/t/regex-with-barcodeinput-component/99387/3 "2024-12-03T22:17:15Z")

</div>

> [@Transistor](#):
>
> I was going to suggest `\r` or `\n` or `\r\n` before the `$` but it doesn't seem to be needed.

I was going to suggest it _instead_ of `$`.

---

<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:** [December 3, 2024, 11:49pm UTC](https://forum.inductiveautomation.com/t/regex-with-barcodeinput-component/99387/4 "2024-12-03T23:49:23Z")

</div>

Apparently JS key event matching (or at least what we do in Perspective) doesn't work in a sane way, so you might need to match against the literal string `Enter` as your end-of-line character?

> [@Perspective Key Event Regex New Line](https://forum.inductiveautomation.com/t/perspective-key-event-regex-new-line/51553/10):
>
> This is expected behavior, all. At the core of the regex match is the data that we receive from a [JavaScript KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent) because this executes in the scope of the browser. We’re assembling a character sequence to match against from an input source (your barcode scanner) that creates KeyboardEvents. A “new line” character shows up as a key press for the “Enter” key. [https://keycode.info/](https://keycode.info/) is a pretty decent way to test what KeyboardEvent data your sequence would produce. It tests a key at a…

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [December 5, 2024, 5:01pm UTC](https://forum.inductiveautomation.com/t/regex-with-barcodeinput-component/99387/5 "2024-12-05T17:01:31Z")

</div>

I have found that I must look for the literal 'Enter' to determine that i have a full barcode.

My question is more - is this expected behavior? Should I expect multiple events before they full string is assembled?

I ask this to make sure my code is futureproof in case some timing changes somewhere, also it will relate to another question I will be asking once I know the answer to this. Thanks
