iOS Question Past a string with letters and numbers into Number type TextField

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all - today one of my clients sent me a screenshot with an error message. I tried to reproduce it and found one unexpected result.

Let's say I have a layout with 2 textfields - in my code they are B4XView.

1 - txtProvider
2 - txtProviderName

txtProvider has Keyboard Type - Number_Pad
txtProviderName has Keyboard Type - Default.

I can't type any letters into txtProvider - on a keyboard I see only numbers. Now how to do the trick - type a string like Jane Doe into txtProviderName, copy it and Past it into txtProvider - it works. Then when I click Submit my code crashes because I don't expect any letters in txtProvider (my code assigns a value from txtProvider to the ProviderID variable which is Int).

I tried to do the same trick with the Android version of my app where I have the same 2 EditBoxes - it's impossible to Past a string with letters into txtProvider.

My question is - how to prevent it from happening in the iOS version? I understand that I need to add a validation but I didn't expect that it's possible.

Thanks.
 

Alex_197

Well-Known Member
Licensed User
Longtime User
I DON'T HAVE B4I

B4X:
Private Sub txtProvider_TextChanged (Old As String, New As String)
    If Not(IsNumber(New)) Then
        txtProvider.Text = Old
    End If
End Sub
Thank you for your reply. Is it possible to prevent Past itself?
 
Upvote 0
Top