Forums > MaxMSP

limit textedit input to just digits using regexp

August 12, 2011 | 8:06 pm

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

August 13, 2011 | 11:41 am

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

August 13, 2011 | 3:36 pm

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


Viewing 3 posts - 1 through 3 (of 3 total)