RegEx for Formatted Text Field

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

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
It’s a fantastic tool for creating regex’s

In particular I use their cheat sheet all the time

1 Like

Also a shoutout to https://regex101.com/r/dMktry/1

1 Like

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.

Closest I got.

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

But it allows multiple periods.

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.

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).

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.