Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Level 7

roKeyboard input validation

Is there a way to check if the text entered in the box is numeric?

type(screen.GetText()) returns String
val(type(screen.GetText())) returns Float (even if the text is not numeric)

Thanks!
0 Kudos
4 Replies
Highlighted
Level 9

Re: roKeyboard input validation

If you just want them to enter a number, you may want to try roPinEntryDialog.
0 Kudos
Highlighted
Level 7

Re: roKeyboard input validation

You can't see what you're typing that way, but otherwise it works. In my case the number is a zip code, so having an incorrect zip code (can't see what you're typing) is probably still better than having an invalid zip code (code with letters in it). But if there is a way to make the PinEntryDialog show numbers as you type, that'd be helpful.
0 Kudos
Highlighted
Level 7

Re: roKeyboard input validation

"peej" wrote:
Is there a way to check if the text entered in the box is numeric?

type(screen.GetText()) returns String
val(type(screen.GetText())) returns Float (even if the text is not numeric)

Thanks!


Here's a somewhat clunky way to do it, but it works.

Function isInteger(MyText as String) as Boolean

if Len(MyText) = 0 return false

for i = 1 to Len(MyText)
digit = Mid(MyText, i, 1)
if Instr(1, "0123456789", digit) = 0 return false
next

return true

End Function

if isInteger(ZipCode)
' Do normal routine
else
' Do error routine
endif
0 Kudos
Highlighted
Level 7

Re: roKeyboard input validation

I like it. Smiley LOL

Thanks.
0 Kudos