Jump to content

whitelist for edit


fairyoggy

Recommended Posts

Posted

* Not tested

local blacklisted = {"A", "a"}
local edit = guiCreateEdit(...)

function editCheck()
    local chars = table.concat(blacklisted, ""):gsub("[%(%)%.%%%+%-%*%?%[%^%$]", "%%%1")
    local editText = guiGetText(source)
    local replacedText = editText:gsub("["..chars.."]", "")
    if editText ~= replacedText then
        guiSetText(source, replacedText)
    end
end

addEventHandler("onClientGUIChanged", edit, editCheck, false)

 

  • Like 1
Posted

@#,xiRocKyz

local zifr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
addEventHandler("onClientGUIChanged", editMoney, function(element) 
	local chars = table.concat(zifr, ""):gsub("[%(%)%.%%%+%-%*%?%[%^%$]", "%%%1")
    local editText = guiGetText(editMoney)
    local replacedText = editText:gsub("["..chars.."]", "")
    if editText == replacedText then
        guiSetText(source, "")
		playSoundFrontEnd(2)
    end
	
	end)

Used your example. If you type numbers(zifr) into the edit. numbers are displayed - fine

If you use other characters, the characters will not be displayed and sound will be played. - fine

BUT If you type "1A" , "213FSDFSFS" and etc - It will work. How to fix it?

Other characters except "zifr" should not be displayed

 

Posted

If you want to whitelist the values that is in the table use this code:

local zifr = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}

function editCheck()
    local chars = table.concat(zifr, ""):gsub("[%(%)%.%%%+%-%*%?%[%^%$]", "%%%1")
    local editText = guiGetText(source)
    local replacedText = editText:gsub("[^"..chars.."]", "")
    if editText ~= replacedText then
        guiSetText(source, replacedText)
        playSoundFrontEnd(2)
    end
end

addEventHandler("onClientGUIChanged", editMoney, editCheck, false)

If you want to simply whitelist all the numbers use this code:

function editCheck()
    local editText = guiGetText(source)
    local replacedText = editText:gsub("[^0-9]", "")
    if editText ~= replacedText then
        guiSetText(source, replacedText)
        playSoundFrontEnd(2)
    end
end

addEventHandler("onClientGUIChanged", editMoney, editCheck, false)

* Both codes are not tested

  • Like 1

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