Single digits

samperizal

Active Member
Licensed User
Longtime User
Greeting.

You can limit the entry into an edit field single digits.


Thank you.
 

Brad

Active Member
Licensed User
Longtime User
I'm assuming that you are asking if it is possible to limit the number of characters entered into a EditText. Take a look at the folllowing code.
B4X:
Sub EditText1_TextChanged (Old As String, New As String)
Dim pline As String
   pline = EditText1.Text
If pline.Length > 39 Then
   EditText1.Text = pline.SubString2(0,39) ' Set the EditText to the first 40 characters
   EditText1.SelectionStart = 39 ' this places the cursor at the end of the text string
' insert code to trigger phone vibrate or display toastmessage
End If
End Sub
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Or the neater
B4X:
Sub EditText1_TextChanged (Old As String, New As String)
If New.Length > 39 Then
   EditText1.Text = Old
   EditText1.SelectionStart = 39 ' this places the cursor at the end of the text string
' insert code to trigger phone vibrate or display toastmessage
End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…