native.newTextField Filter Words Questions?

I had a question about the native.newTextField API. I wanted to make it so that users can’t input bad words, but currently I only have thought of one way to do it:

[lua] if chatbox.text == ‘*****’ then native.showAlert( “YOU HAVE BEEN WARNED”, “You are banned”, { “Accept”}) return end[/lua]

Would anyone know how to make it so that if a user types a sentence, and that one word appears, then this message pop’s up?

API Link: http://developer.anscamobile.com/reference/index/nativenewtextfield

Regards,
Jordan Schuetz
Ninja Pig Studios [import]uid: 29181 topic_id: 22583 reply_id: 322583[/import]

Well you could setup an enterFrame listener and check the text every frame to see if the word shows up. I did that in an app to show the length of the text entered (well it was a count down length for a text message)
[import]uid: 19626 topic_id: 22583 reply_id: 90005[/import]

Would it be possible to write a short example, I really have no idea how to do that. Thanks Rob, I appreciate your reply.

Regards,
Jordan Schuetz
Ninja Pig Studios [import]uid: 29181 topic_id: 22583 reply_id: 90007[/import]

  
local alertShown = false  
  
local function checkForBadWords(event)  
 local badWordDetected = false  
 if string.find(chatbox.text,"badword1",1,true) then badWordDetected = true end  
 if string.find(chatbox.text,"badword2",1,true) then badWordDetected = true end  
 if string.find(chatbox.text,"badword3",1,true) then badWordDetected = true end  
 if not alertShown then  
 alertShown = true  
 native.showAlert( "YOU HAVE BEEN WARNED", "You are banned", { "Accept"})  
 end  
  
end  
  
Runtime:addEventListener("enterFrame", checkForBadWords)  

Of course, you would need your native alert to call back and reset the alertShown to false.

or something like that… [import]uid: 19626 topic_id: 22583 reply_id: 90021[/import]

Thanks Rob! Appreciate it!

Regards,
Jordan Schuetz
Ninja Pig Studios [import]uid: 29181 topic_id: 22583 reply_id: 90030[/import]

Also to save having a huge amount of if statements, put all the words you want to filter into a table and run a for loop based on that. [import]uid: 84637 topic_id: 22583 reply_id: 90034[/import]