This was not done by me.
I think it's agraham who wrote this code.
I think the number 2 is correct for your needs.
B4X:
Sub TextBox1_KeyPress (key)
If StrLength( textbox1.Text) >=[COLOR="Red"]2[/COLOR] Then
If Asc(key)>31 Then
ss = Textbox1.SelectionStart
Textbox1.Text= SubString(Textbox1.Text,0,[COLOR="red"]2[/COLOR])
Textbox1.SelectionStart = ss
End If
End If
End Sub
Sub App_Start
AddEvent("TextBox1",KeyPress,"TextBox_maxC5_KeyPress")
AddEvent("TextBox2",KeyPress,"TextBox_maxC5_KeyPress")
Form1.Show
End Sub
Sub TextBox_maxC5_KeyPress (key)
If StrLength(Control(Sender))=5 AND _
( IsLetter(key) OR IsNumber(key) ) Then
Control(Sender).IgnoreKey
End If
End Sub