limit textedit input to just digits using regexp

Aug 12, 2011 at 8:06pm

limit textedit input to just digits using regexp

I’m using code posted by Alex Harker (in turn built on work of Luke Hall) found elsewhere in the forum, to limit the number of characters entered in a textedit to a specific maximum number (5). I would also like to limit the input to *just* digits 0-9, no other characters. I tried to modify the regexp expression with info I found online, but I’m failing miserably.

Can anyone help?

– Pasted Max Patch, click to expand. –
#58450
Aug 13, 2011 at 11:41am

This works I believe. using a little extra max processing

The regexp is outputting a list of any digits found in its input string from the substrings outlet. I’m then filtering any spaces (32′s) from this list via an [atoi]/[itoa] pair and a [zl filter 32]. When you get a non-matching input (e.g. the string “a”) I’m clearing the textedit object.

– Pasted Max Patch, click to expand. –
#210057
Aug 13, 2011 at 3:36pm

Very nice, thanks! I was stuck in thinking about how to do it with just regexp, but this is a nice hybrid solution.

#210058

You must be logged in to reply to this topic.