limit textedit input to just digits using regexp

Dan Nigrin's icon

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.

Max Patch
Copy patch and select New From Clipboard in Max.

Can anyone help?

willyc's icon

This works I believe. using a little extra max processing

Max Patch
Copy patch and select New From Clipboard in Max.

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.

Dan Nigrin's icon

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