How to limit the max length of typed user input
One of the parameters I am managing in my patch has a text name that is a maximum of 20 characters long.
There seems to be no way to limit the text input into a textedit object, nor a dialog object.
Can anyone tell me how to pop up a box asking for user input, and limit the number of characters to a maximum of 20?
With a combination of:
– Script gets fed ASCII characters with a [key] object
– Bangs to toggle ‘process/drop keypresses’ (as [key] is always live)
– Parameter to set the maximum number of characters allowed
– Parameter to determine the destination of the string being output (I am using pattr to distribute these across my patch/subpatches)
– Parameter to specify a filter to limit input to allowed characters
… it makes a pretty good general purpose keyboard handler.
If there is an object in Max which can do this already, I’d be grateful for that info, I’ve had a good search around but couldn’t find anything obvious!
You can atoi -> zl slice 20 -> itoa…
I prefer Max over js or regexp. Its much more readable…
It may be too messy, but you could always just have a clickable keyboard of message boxes instead. A bit more work up front, but you can easily restrict the number of chars entered, as well as filter out illegal chars by simply not having them available.
----------begin_max5_patcher---------- 712.3ocuX1saiBCDE9ZxSgEW0HwFwX9M6Eqz9bzFshDbItBLQfi1zV028EaC ooYSJjfw2.XaBb7Gyb7379LK60kGH01nehdDYY89LKKYWhNrZaaYWjbXSdRs 71rKH00IYDaG0Xk644DN+0cD0Cw1FspcnmKY7Z5axA.7B21t2kv2rkxx9SEY CW8iB8ZFEAQQhSQKkMhW3d7Iw1WPYMuFoBve1o5kK6EZ6klJUY45W9Qnq8IJ gkTHUh8uqnI41hA9X1LwAmANyYj+17X6dlbxAo5s4nbT90wgy8gD.qXRfu3T P3h.GD18ZLAtHSv+OSBhMBSpZTAAsNgkocvDIAB3ItITXr3nN3B1Hb44pxh5 WKVWlq07GHDjbHNTl.4cOP4BIPAfQfxtJxNBKEUS3SAU7bkAIp3FMPEeOiPk 2xQUD8m9zEpDp7U5I+AOz7Geyj+TSxQvUYhxuYbbwW5q3EpKtXlTnegfkWEK TFeLDQPAGjObOD4RoOFZU4xoymEhjgGAK0jiB12HH4kZdEMKiTgdH4Q2UKxI rL914sspyoaHO39zShoz74SkwCrTY4.QZZkaLXnp7V+89N2coL9pkq00xS.X vJ7jMmnJ7.ouSHno3DMupsXlSRoe+rW375LVPzUiqxF9FAg+EBPFFHjuE6bJ 67sGJEpn+uRm5x8Ua5l7ca0.8oXSI0bJKgSKYmbSh8ngfi2zVZZJQNdGVJno 6Ja3XqHPqt32paRSPOZRXGehvmbMgGflNClSslD03162N31jDD4J1DqmmLP1 KVZ680VgAhiMWGntdjyBwRC8RVe7sEA50jOJ1KdmwzxisFoZGBxkwJFLzDFf lNKVYxCMwCgSfQ0DdPbx0rbxcHZxrbxePbxrw3m41ekkDLKm.P+1uiURMuMu 9TzMJIweBQvwJ8vwwmT2WaKe2OWQPU6ynmE8w0wXm0z3iY+C0MnSfB -----------end_max5_patcher-----------
It also satisfies my main objective which was not to take a longer existing string and truncate it to N characters but to prevent more than N characters being entered in the first place.
Thanks to everyone for picking this up.
Man, where the heck did [jstrigger] come from? Totally new to me…
Interesting to see how the various combinations of commas and semicolons and backslashes are handled by various objects, like message boxes or sprintf, it can get kind of strange…but I guess that kind of thing is expected when you need to reserve characters for other purposes in some cases (like an expr object), but not in others (like a comment)…am still learning every day.
OK – I realise this is done and solved, but I thought I’d see how few objects I could do this in. This is what I got, which should give the same behaviour as the patch above in case anyone is interested in a regexp approach:
----------begin_max5_patcher---------- 510.3ocwUFriaBCDF9L7TX4SsRoQX.GH8VeNpVUAgIY8pfMxXTy1n7tW7.rI axthDha5Av3wlw+9y+Lr22ilq1A0Tx2I+j34s22yCCYC3022iVlsa01rZbZT I7aU9KzYcCYfcFL7Zspr90xb01ggVqjlZwe.6vrv4A8gkMkB4VvfYi0GrJyr 5YgbyuzvJSmZX7312gvVtv1jDYuGFLOf7zwDoZLmmIQAJmVI9MV7oRQlUhRg 9CsH6MQ1kAyqUP2pRojmribv22da18AkJMTAxBRMXbKUBYKQpDe6TI4+MTzv FXWE4Ky2GFb3qthKQonaIgYaRGysvujKSxrL6rKmxo1kCH4YxMNhQonmgEmX aVjNBhBuDQ7voxHWxECI2o.g2QhI7oDiMAdfGnt2mfccpOIji9D1s6Shdn1D 6NGJDlK.ScwZx5lMunagAnMMZCncJhFJyDXah+bDE+AVmIhHgz7wEavkltUH O+u4n5sweOBqUM5UCYd3ukji6fBn1HjYFgRdxjRd2bdVTT.3vC7qTTToZ0Xu F9jyyqURVEwFQQmI6+0RxVBbTM8XkTxUbtwtMEwVDMmaqIhkFWv6JPdRmDz+ uL0NK6y24VfcEagnGJTsJJZLndiTMrkT72JrFEDcRY19db9QtZe9d2EL26Mt SIEcEJB+HapRpsyA++xE35NM -----------end_max5_patcher-----------
Resurrecting an old post – Alex that’s pretty slick with the regexp! But I have a need to limit the input to just ten *digits.* So I tried to modify the regexp to do so, and it works to limit the number of digits, but not to reject any alpha characters. What am I doing wrong?
----------begin_max5_patcher---------- 496.3ocyU11aBBCDG+0vmhl9psDmwxyr2sOGalEP5ztHsDnloy3280dfOFEb BRzDobWK28u+335ZSCbrXIs.idE8NxvXsogA3R6vnx1.mFsbx7nBXYXN8GQ7 23AkSIoKkf6uxEoEqRiEy2NkXgbNUJWkQKCOFiFWM0WBtrf8KLAwZ3nJ27Eo Lt5YfDQpbxRf3qx4KDmswNKRNYFiO8yb5DYY3IdiTABQB8zC915qVJWGkTdT JjT7a4rncJUk2RwVlXsyMll5KCZGTxxoYTdBpfJueTwuYnXQBAn37H.kb5T5 xLzSen9kr1cyyWFMCN4eaQUs0O1AP8iOAFF4cyrxsCYkJrTTbDeZ8Ppsfw0p FxD.EODGe8fWvMyEqtiKRT7EABPqV2pgzHPbKIwiw2TPcBXdWqSratLwxEJS H8ZYhdmSSX0u6YbYm0Io4xifpSffFvN2BHbN.DvCimy3mdXMjes+ioSgXQ9j sa9pVeHxNIjPKjLdjjI3GrF84qn85bFKIgByukJorjLgBiUZ.M9ruptVIoa5 znl5WIYeT1Nuh.Y2eRR2IpQMQ5WIoxlcSJ5eJIK+vgt6ZeXOx9flIUVtfQXf dc566fcQSb0tW4pe2+ll3AX0xANrxys7HqCL7C2CU88sEpNWwdvuETUYrw7O tPE4vA -----------end_max5_patcher-----------
Forums > MaxMSP