mrossen Active Member Licensed User Longtime User Jan 23, 2020 #1 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
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
Erel B4X founder Staff member Licensed User Longtime User Jan 26, 2020 #2 Why aren't you setting the Keyboard Type property to Numbers or Decimals? Upvote 0
mrossen Active Member Licensed User Longtime User Jan 26, 2020 #3 I have set keyboard to numbers. Works fine on iPhone but not on iPad. There I got the standard keyboard Upvote 0
I have set keyboard to numbers. Works fine on iPhone but not on iPad. There I got the standard keyboard
Erel B4X founder Staff member Licensed User Longtime User Jan 26, 2020 #4 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
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