Jump to content

GUI Edit Input blacklist


Recommended Posts

Anyone knows why there are special character like "$" not working with the following code:

gButtons.bet_input = guiCreateEdit( 0.605, 0.965, 0.07, 0.0225, "other", true ) 
guiEditSetMaxLength (gButtons.bet_input, 128 ) 
     
characterBlackList = {"Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","M","N","B","V","C","X","Z","q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m","|","!","@","#","$","%","^","&","*","(",")","-","=","+","_" 
    } 
     
addEventHandler("onClientGUIChanged", gButtons.bet_input, function(element) 
    for c,l in ipairs (characterBlackList) do 
        if (string.find(guiGetText(element),l)) then 
            local text  =  string.gsub(guiGetText(element),l,"") 
            guiSetText(element,text) 
        end 
    end  
end) 

Link to comment

Because it accepts a Lua pattern, which means you'll need to escape it.

Either way, you can save yourself a lot of code by simply doing this:

  
addEventHandler("onClientGUIChanged", gButtons.bet_input,  
    function(element) 
        local text = guiGetText(element) 
        if not tonumber( text ) then 
            local changedText = string.gsub(text,"%D","") 
            if changedText ~= text then 
                guiSetText ( element, changedText ) 
            end 
        end 
    end 
) 
  

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...