DakiLLa Posted October 6, 2012 Posted October 6, 2012 Hi. I want to prevent users typing in some characters in edit field, such as "[", "]" (square brackets), and "^". How can I do that? Right now I'm using the next pattern: string.gsub( someText, '[^A-z, ^0-9]', '' ) Thx in advance.
Kenix Posted October 6, 2012 Posted October 6, 2012 local s = 'Kenix^' if s:match( '[%[%^%]]' ) then print 'n' else print 'y' end --> n You mean it?
DakiLLa Posted October 6, 2012 Author Posted October 6, 2012 (edited) I don't need to check wether or not there are special chars in the string. I want to make it fix the string automatically, like 'gsub' does. Edited October 6, 2012 by Guest
Kenix Posted October 6, 2012 Posted October 6, 2012 local s = 'Kenix^^^[[[]]]' print( s:gsub( '[%[%^%]]', '' ) ) --> Kenix
DakiLLa Posted October 6, 2012 Author Posted October 6, 2012 One more question: how to exclude '\' char ?
Kenix Posted October 6, 2012 Posted October 6, 2012 (edited) local s = 'Kenix\\1' print( s ) -- > Kenix\1 print( s:gsub( '\\', '' ) ) --> Kenix1 Well if you have string like this it's unfinished string print( '\' ) P.S \ is hided in bb code. So if you want use \ char you need: print( '\\' ) --> \ Edited October 6, 2012 by Guest
DakiLLa Posted October 6, 2012 Author Posted October 6, 2012 Ah ye, there was a mistake in my code, so I thought '\\' won't work. It works now, thanks again.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now