Desaster Posted October 30, 2013 Share Posted October 30, 2013 how to enable a sting format like I want just numbers in my edit box if you type any other thing it won't be written Link to comment
Castillo Posted October 30, 2013 Share Posted October 30, 2013 You can use the event onClientGUIChanged with guiSetText and string.find. Link to comment
Desaster Posted October 30, 2013 Author Share Posted October 30, 2013 useful but i need an other thing I am making a edit box where you should put your the ammo you want and I want that the player just type numbers no text Link to comment
Desaster Posted October 30, 2013 Author Share Posted October 30, 2013 what's the problem here ? local text = guiGetText ( ammotext ) guiGridListSetItemText (ammoGirdcart, row2, 1, wepName1, false, true) guiGridListSetItemText (ammoGirdcart, row2, 2, text, false, true) guiGridListSetItemText (ammoGirdcart, row2, 3, wepCost1, false, true) ) ps: this is in a fuction Link to comment
Castillo Posted October 30, 2013 Share Posted October 30, 2013 This is an small example: local curText = "" local editBox = guiCreateEdit ( 100, 50, 150, 150, "", false ) addEventHandler ( "onClientGUIChanged", editBox, function ( ) local text = guiGetText ( source ) if ( text == "" ) then curText = "0" guiSetText ( source, "0" ) return end if ( not tonumber ( text ) ) then guiSetText ( source, curText ) else curText = text end end, false ) Link to comment
Moderators Citizen Posted October 30, 2013 Moderators Share Posted October 30, 2013 Here is the more simple checker that you can do: local editBox = guiCreateEdit(0.3,0.1,0.4,0.1,"",true) addEventHandler("onClientGUIChanged", editBox, function() local text = guiGetText(source) or "" if not tonumber(text) then --if the text isn't a number (statement needed to prevent infinite loop) guiSetText(source, string.gsub(text, "%a", "")) --Remove all letters end end) It will remove all letters that are written into a memo or an editbox. Here I used an editbox at line 1, be sure to paste this addEventHandler right after the creation of your editbox and replace the variable at line 2 to match your editbox variable. EDIT: Oh and you only can write rounded numbers, you can't write a number like this: 100.5 Link to comment
Castillo Posted October 30, 2013 Share Posted October 30, 2013 But that won't remove the characters ( $, %, /, etc ). Link to comment
Desaster Posted October 30, 2013 Author Share Posted October 30, 2013 how to add this function to your function castillo ? guiGridListSetItemText (ammoGirdcart, row2, 2, text, false, true) Link to comment
.:HyPeX:. Posted October 30, 2013 Share Posted October 30, 2013 if you want to remove stuff try string.gsub with custom patterns. i used this to change all caps to non-caps and hex colours. (in this case, from an account data) local named = getAccountData(playerAccount, "name") -- Get the string local namedd = string.gsub(named, "#%x%x%x%x%x%x", "") --Remove Hex Colour local named1 = string.gsub(namedd, "[A]", "a") -- start replacing characters local named2 = string.gsub(named1, "", "b") local named3 = string.gsub(named2, "[C]", "c") local named4 = string.gsub(named3, "[D]", "d") local named5 = string.gsub(named4, "[E]", "e") local named6 = string.gsub(named5, "[F]", "f") local named7 = string.gsub(named6, "[G]", "g") local named8 = string.gsub(named7, "[H]", "h") local named9 = string.gsub(named8, "", "i") local named10 = string.gsub(named9, "[J]", "j") local named11 = string.gsub(named10, "[K]", "k") local named12 = string.gsub(named11, "[L]", "l") local named13 = string.gsub(named12, "[M]", "m") local named14 = string.gsub(named13, "[Ñ]", "ñ") local named15 = string.gsub(named14, "[N]", "n") local named16 = string.gsub(named15, "[O]", "o") local named17 = string.gsub(named16, "[P]", "p") local named18 = string.gsub(named17, "[Q]", "q") local named19 = string.gsub(named18, "[R]", "r") local named20 = string.gsub(named19, "", "s") local named21 = string.gsub(named20, "[T]", "t") local named22 = string.gsub(named21, "", "u") local named23 = string.gsub(named22, "[V]", "v") local named24 = string.gsub(named23, "[W]", "w") local named25 = string.gsub(named24, "[X]", "x") local named26 = string.gsub(named25, "[Y]", "y") local named27 = string.gsub(named26, "[Z]", "z") this is how it should work: local Whatever-You-Want = string.gsub(string-To-Check, "Thingy-To-Search", "Remove-With") This is a list with all patterns: http://www.gammon.com.au/scripts/doc.ph ... tring.find Link to comment
Moderators Citizen Posted October 30, 2013 Moderators Share Posted October 30, 2013 But that won't remove the characters ( $, %, /, etc ). Hmmm you right, then this: local editBox = guiCreateEdit(0.3,0.1,0.4,0.1,"",true) addEventHandler("onClientGUIChanged", editBox, function() local text = guiGetText(source) or "" if tonumber(text) then return end local newText = "" for k=0, #text do local char = string.sub(text, i, i) if tonumber(char) then --it's a number newText..char end end guiSetText(source, newText) end) Link to comment
myonlake Posted October 31, 2013 Share Posted October 31, 2013 It's never going to work like you think it will. I've tried the same many times and by spamming my keyboard it always adds another character which I don't want. I think you should just allow all characters and then strip them off later. Link to comment
Spajk Posted October 31, 2013 Share Posted October 31, 2013 I dont know if this is going to work, but you can try the combination of onClientGUIFocus, onClientGUIBlur and onClientKey with cancelEvent() Link to comment
DakiLLa Posted October 31, 2013 Share Posted October 31, 2013 how to enable a sting format like I want just numbers in my edit box if you type any other thing it won't be written yourGUIEdit = guiCreateEdit( ... ) addEventHandler( "onClientGUIChanged", yourGUIEdit, function() local currText = guiGetText( source ) local newText = string.gsub( currText, '[^0-9]', '' ) if newText ~= currText then guiSetText( source, newText ) end end, false ) Link to comment
Desaster Posted October 31, 2013 Author Share Posted October 31, 2013 thnx all that helps me alot Link to comment
Spajk Posted November 10, 2013 Share Posted November 10, 2013 (edited) Hello, I am bumping this topic as I found a really nice and efficient way of allowing only numbers in edit fields ( or anything else you want ). guiSetProperty(editBox, "ValidationString", "^[0-9]*$") This is just an example, it uses regex and can be used for any kind of input filtering. Edited November 10, 2013 by Guest Link to comment
Desaster Posted November 10, 2013 Author Share Posted November 10, 2013 hmmmm seems nice Link to comment
DakiLLa Posted November 10, 2013 Share Posted November 10, 2013 Hello, I am bumping this topic as I found a really nice and efficient way of allowing only numbers in edit fields ( or anything else you want ). guiSetProperty(editBox, "ValidationString", "^[0-9]*$") This is just an example, it uses regex and can be used for any kind of input filtering. Thank you. Link to comment
Desaster Posted November 17, 2013 Author Share Posted November 17, 2013 guiSetProperty(editBox, "ValidationString", "^[0-9]*$") hmmm I tested this and I found out that it has a bug you can copy any text and paste it in it and then you have a text written in it (bad) the best one is that one with tonumber Link to comment
Spajk Posted November 17, 2013 Share Posted November 17, 2013 Hmmm, I will try to find a better way tomorrow Link to comment
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