I'm working on a Roku app and we want the user's date of birth. Trying not to get too complex on the parsing end (so would prefer to not just have a text box where the user can enter whatever they want). I looked into using a roPinEntryDialog
, but that unfortunately I think is only meant for entering payment information. I see that roDateTime
is a thing, but that seems to only get the current date, and not have any types of inputs for it.
Any ideas or help?
Thanks!
The solution I ended up using was to use a regular text keyboard, and validate the input with regex:
getText: function(ageValidate as Boolean, defaultText as String, displayText as String) as String
screen = CreateObject("roKeyboardScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.SetDisplayText(displayText)
screen.SetText(defaultText)
screen.SetMaxLength(100)
screen.AddButton(1, "done")
screen.AddButton(2, "back")
screen.Show()
while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roKeyboardScreenEvent"
if msg.isScreenClosed()
return ""
else if msg.isButtonPressed() then
if ageValidate = true AND m.isValidDate(text) = false then
"Invalid Input", "Input your birthdate in the format MMDDYYYY", "okay")
else if text = invalid OR text = ""
showUserDialog("Error"), "no input", "okay")
else
screen.Close()
return text
end if
else if msg.GetIndex() = 2
screen.Close()
return ""
end if
end if
end if
end while
end function
isValidDate: function(date as String) as Boolean
return CreateObject("roRegex", "(0[1-9]|1[012])[-.]?(0[1-9]|[12][0-9]|3[01])[-.]?(19|20)[0-9]{2}", "i").IsMatch(date)
end function