B4J Code Snippet TextField Numeric Input only

Discussion in 'B4J Code Snippets' started by Jmu5667, Oct 11, 2018.

  1. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Hi all

    Here is how I handle numbers only input for a text field.


    Code:
    Sub txtField_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 > 15 Then   ' 15 is the max length allowed you can change this :)
           text = text.SubString2(0,15)
           update = 
    True       
       
    End If
       
       
    If update Then
           txtField.Text = text
           txtField.SetSelection(text.Length,text.Length)
       
    End If


    End Sub
    Regards

    John
     
    behnam_tr, Edgardo Nakaya and walt61 like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice