iOS Question B4XFloatTextField, validate text

mrossen

Active Member
Licensed User
Longtime User
Hi,

How do I validate input correct correct. There is no lost focus event

I try to catch all there is not numbers.

B4X: Copy
Sub B4XFloatTextField1_TextChanged (old As String, new As String)
    If IsNumber(new) = False Then
        new = old
        B4XFloatTextField1.text = old
    End If
End Sub

This does not change the text, and if I try.

B4X: Copy
Sub B4XFloatTextField1_TextChanged (old As String, new As String)
    If IsNumber(new) = False Then
        new = old
        B4XFloatTextField1.text = "0"
    End If
End Sub

It seems to fire event again.

Mogens
 
I have set keyboard to numbers. Works fine on iPhone but not on iPad. There I got the standard keyboard
 
Upvote 0
You are correct. Consider using B4XInputTemplate or if you have several fields, B4XPreferencesDialog. They are simple to use and cover these cases.

Code to remove non-numbers while the user types (should be done carefully):
Code: Copy
Sub B4XFloatTextField1_TextChanged (Old As String, New As String)
    If New <> "" And IsNumber(New) = False Then
        Sleep(0)
        If IsNumber(Old) Then
            B4XFloatTextField1.Text = Old
        Else
            B4XFloatTextField1.Text = ""
        End If
    End If
End Sub
 
Upvote 0
Back
Top