iOS Question [SOLVED] Regex / Textfield / How to handle also first character?

christianjeannot

Member
Licensed User
Hi Community,

as number pad has no return / done button I am using the code from this thread to be able to have numeric values in the text field.

B4X:
Private Sub txtNumberNumber_TextChanged (Old As String, New As String)
    Dim update As Boolean
    
    Try
        Dim text As String = Regex.Replace("\D", New, "")
        If New <> text Then
            update = True
        End If
    Catch
        Log(LastException.Message)
    End Try
    
    If text.Length > 3 Then
         text.SubString2(0,3)
         update = True
    End If
    
    If update Then
        txtNumberNumber.Text = text
        txtNumberNumber.SetSelection(text.Length,text.Length)
    End If
    
End Sub

This is working when i entered 2 characters. It is not working when I enter only 1 character.

Is it possible to have this working when also entering only one char or did I have made something wrong?

Best regards

--Christian
 

christianjeannot

Member
Licensed User
I tested it. It works

Do I have to do
B4X:
Root1.AddView(txtNumberCount, 0, 0, 200, 100)
for every text field where I needed the expanded keyboard?

Or is AddView not necessary?
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…