# RegEx for Formatted Text Field

**URL:** <https://forum.inductiveautomation.com/t/regex-for-formatted-text-field/36036>\
**Category:** Ignition\
**Created:** [June 25, 2020, 2:53pm UTC](https://forum.inductiveautomation.com/t/regex-for-formatted-text-field/36036 "2020-06-25T14:53:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![boyergary](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/boyergary/32/10316_2.png) [@boyergary](https://forum.inductiveautomation.com/u/boyergary)\
**Post date:** [June 25, 2020, 2:53pm UTC](https://forum.inductiveautomation.com/t/regex-for-formatted-text-field/36036/1 "2020-06-25T14:53:42Z")

</div>

In a formatted text field, I’m trying to allow a user to put in a whole number or a decimal number with one number after the decimal. It seems to not matter what RegEx pattern I use, it won’t allow me to type a decimal point. It limits the input to numbers, but just ignores the decimal (period) when I type it.

I’ve tried all different types of RegEx, this being the most recent: ^[1-9]\d\*(.\d+)?$

Thanks,  
Gary

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 25, 2020, 4:55pm UTC](https://forum.inductiveautomation.com/t/regex-for-formatted-text-field/36036/2 "2020-06-25T16:55:54Z")

</div>

A dot in regex means any char except line break. You have to escape it with `\.`

If you don’t already use it, I would definitely recommend [www.regexr.com](http://www.regexr.com)  
It’s a fantastic tool for creating regex’s

In particular I use their cheat sheet all the time

 ![20200626_023119](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/c/9caaa4ca6d704f853ac277b9953c979eec2d0c1b.jpeg)

---

<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:** [June 25, 2020, 4:58pm UTC](https://forum.inductiveautomation.com/t/regex-for-formatted-text-field/36036/3 "2020-06-25T16:58:51Z")

</div>

Also a shoutout to [https://regex101.com/r/dMktry/1](https://regex101.com/r/dMktry/1)

---

<div class="post-metadata">

**Author:** ![boyergary](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/boyergary/32/10316_2.png) [@boyergary](https://forum.inductiveautomation.com/u/boyergary)\
**Post date:** [June 25, 2020, 5:40pm UTC](https://forum.inductiveautomation.com/t/regex-for-formatted-text-field/36036/4 "2020-06-25T17:40:51Z")

</div>

Yes, I actually tried this (escaping .) and it works with regular regex in a python statement, but doesn’t seem to work in the regex field of a formatted text field.in Ignition.

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [June 25, 2020, 7:57pm UTC](https://forum.inductiveautomation.com/t/regex-for-formatted-text-field/36036/5 "2020-06-25T19:57:13Z")

</div>

Closest I got.

^((\d+([.]\d{0,1})_)|([.]\d{0,1})|()|\s_)$

But it allows multiple periods.

---

<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:** [June 25, 2020, 9:23pm UTC](https://forum.inductiveautomation.com/t/regex-for-formatted-text-field/36036/6 "2020-06-25T21:23:19Z")

</div>

A regex pattern of `\d+(\.\d)?` seems to work pretty well; it won’t allow `1234.` or `123.45` but will allow `123.4`. Technically you could start with a 0, so `0.1` would be accepted; not sure if that’s a deal breaker.

---

<div class="post-metadata">

**Author:** ![boyergary](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/boyergary/32/10316_2.png) [@boyergary](https://forum.inductiveautomation.com/u/boyergary)\
**Post date:** [June 26, 2020, 12:48pm UTC](https://forum.inductiveautomation.com/t/regex-for-formatted-text-field/36036/7 "2020-06-26T12:48:34Z")

</div>

Did you try using this in a Formatted Text Field?? It still won’t let me type in a decimal (period). I have Allow Invalid Text set to False (which is required to follow the regex pattern).

---

<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:** [June 26, 2020, 2:26pm UTC](https://forum.inductiveautomation.com/t/regex-for-formatted-text-field/36036/8 "2020-06-26T14:26:00Z")

</div>

Yeah, I tested in a formatted text field. The only setting I changed from default (besides the pattern) was to change the update mode to ‘Revert’ instead of ‘Commit or Revert’. I didn’t play around with it much, though, to be fair.
