Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
peej
Visitor

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 4
RokuKevin
Visitor

Re: roKeyboard input validation

If you just want them to enter a number, you may want to try roPinEntryDialog.
0 Kudos
peej
Visitor

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
WilDD
Roku Guru

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
peej
Visitor

Re: roKeyboard input validation

I like it. Smiley LOL

Thanks.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.