|
| 20 Aug 2013 05:21 PM |
| My intent is to only allow them to enter in numbers. How do I check to see if they put in letters? |
|
|
| Report Abuse |
|
|
josh50000
|
  |
| Joined: 29 Nov 2009 |
| Total Posts: 697 |
|
|
| 20 Aug 2013 05:28 PM |
| I had this problem a while ago and the best solution I could come up with is to check the length of the inputted string and then compare that to the length of the same string with the letters removed using string.match. If the two lengths are the same then the string does not contain any letters. |
|
|
| Report Abuse |
|
|
josh50000
|
  |
| Joined: 29 Nov 2009 |
| Total Posts: 697 |
|
|
| 20 Aug 2013 05:32 PM |
| http://wiki.roblox.com/index.php/String_patterns |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Aug 2013 05:36 PM |
OR you can make it invisible or a textlabel that looks like a textbox EVER THOUGHT OF THAT THAT |
|
|
| Report Abuse |
|
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
|
| 20 Aug 2013 05:57 PM |
The only reason I'm giving you this/Scripting it for you is because I've had the same problem before and wanted to make something for that problem. It's probably not the best way, but it works. If you know what you're doing you can easily implement it in to your script.
local check = script.test --stringvalue in script
local checkTest = function() for letters = 1, check.Value:len() do for nums = 0, 9 do val = string.sub(tostring(check.Value), letters, letters) if nums == tonumber(val) then print("Value: " ..letters.. " is a number ["..nums.."]") elseif tonumber(val) == nil then print("Value: " ..letters.. " is not a number.") return false end wait() end end return true end
function startTest() check123 = checkTest() if check123 then print("yay all numbers") else print("Lame, there's a letter!") end end
startTest()
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Aug 2013 06:00 PM |
You guys are not very smart -.-
local BlockInput = true local LastInput = script.Parent.Text script.Parnet.Changed:connect(function() script.Parent.Text = LastInput end) |
|
|
| Report Abuse |
|
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
|
| 20 Aug 2013 06:11 PM |
| No, TextBox doesn't fire .Changed() when you type. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 06:12 PM |
@Cnt Read the thread before you post @Others I made my own script after josh's first post. I hadn't realised this thread had gotten so many replies
My script is located in a TextBox, and is extremely simple:
script.Parent.Changed:connect(function() NumberString = string.match(script.Parent.Text, "%d+") Number = tonumber(NumberString) if Number > script.Parent.Parent.Parent.MaxAmount.Value then script.Parent.Text = tostring(script.Parent.Parent.Parent.MaxAmount.Value) else script.Parent.Text = NumberString end end)
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Aug 2013 06:12 PM |
| It doesn't? WDF ROBLOX WHAT HATHIT YOU DUN! |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Aug 2013 06:13 PM |
Ohh
Well, it's still easy:
if not tonumber(script.Parent.Text) then --not a number script end |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 06:13 PM |
| It fires when you press the Enter key. |
|
|
| Report Abuse |
|
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
|
| 20 Aug 2013 06:15 PM |
| Yeah, but you don't need .Changed if you're using an enter key. @cnt xd I guess if you want to figure out where they're entering a letter you can still use mine lol. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 06:16 PM |
"You guys are not very smart -.-
local BlockInput = true local LastInput = script.Parent.Text script.Parnet.Changed:connect(function() script.Parent.Text = LastInput end)"
You're making a fool out of yourself. If you were to have actually read my post, you'd understand I wanted only numbers in my text box, not letters. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 06:17 PM |
@Azarth
That's a roblox function, not part of my script. The 'text' property is changed once you press Enter or click anywhere out of the textbox. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
josh50000
|
  |
| Joined: 29 Nov 2009 |
| Total Posts: 697 |
|
|
| 20 Aug 2013 06:18 PM |
| Yeah that will work fine, in my case I wanted the player to renter the data if it contained anything other than numbers in the string so that's why I wrote about comparing lengths. |
|
|
| Report Abuse |
|
|