Regex attribute for text boxes

Hello,

I was thinking how useful it would be to have something for a text box, where we could set the allowed characters.

I also found a post somewhat similar to this, which requested a min max option for numbers.

The easiest option would be to have a regex setting for a text_box. There you could specify basically anything.

And yes I know we are able to do it via change event, but I prefer the more lazy approaches.

As a lazy person, I find regex to be much higher on the effort spectrum than something like:

  def text_box_1_change(self, **event_args):
    if len(self.text_box_1.text) > 6:
      self.text_box_1.text = self.text_box_1.text[:6]

or some other character comparison, but I do understand that some people use regex every day with no problems.

3 Likes

Learning regex is easy. I’ve done it hundreds of times!

9 Likes

Me too!

The Vitamin C library (yes, I’m dating myself) allowed a “picture” to define the input pattern, e.g.,

$###,###.## (with “right-to-left” entry before the decimal point, and left-to-right after)
(999) 999-9999x9999
Aaaaaaaaaa

The input field stayed formatted as you typed, the cursor was controlled for you (by default), so there was no ambiguity whatsoever. Paste in a pre-formatted value, e.g., “$31,071”, as from a PDF, and it would accept it, no problem. (We can’t do that with the current text field; it blanks as soon as you tab away.)

That’s nearly as “lazy” as I can think of.

1 Like

Unfortunately I am working in a network project with lots of specified text formats and I would not prefer to do the format checkups via multiple if cases. That is why I would prefer a simple regex check.

I can agree, that regex can be hard at first. I was there as well, but the more you use it the easier it becomes. In addition most of the special formats I work with were already specified on websites like stackoverflow. So there isn’t that much of work needed as others would think.

In the few cases when I want auto formatting I use the Validator.

Using it only for auto formatting wouldn’t be as simple as the property you are requesting, but since I’m using it already for input validation, adding the auto formatting is pretty simple.