Hi All.
I'm trying to develop a sub to format my text field with the mask XXX.XXX.XXX-XX.
It's acceptable only numbers. This is a point in iPad device, cause I can't discover any way to restrict the input for numbers.
I'm using this code.
I'm trying to develop a sub to format my text field with the mask XXX.XXX.XXX-XX.
It's acceptable only numbers. This is a point in iPad device, cause I can't discover any way to restrict the input for numbers.
I'm using this code.
B4X:
Sub txtDocumentNumber_TextChanged(OldText As String, NewText As String)
Log ("OldText " & OldText)
Log ("NewText " & NewText)
If (DocType = "CPF") Then
If (NewText.CharAt(NewText.Length - 1) = "1" OR NewText.CharAt(NewText.Length - 1) = "2" OR NewText.CharAt(NewText.Length - 1) = "3" OR _
NewText.CharAt(NewText.Length - 1) = "4" OR NewText.CharAt(NewText.Length - 1) = "5" OR NewText.CharAt(NewText.Length - 1) = "6" OR _
NewText.CharAt(NewText.Length - 1) = "7" OR NewText.CharAt(NewText.Length - 1) = "8" OR NewText.CharAt(NewText.Length - 1) ="9" OR _
NewText.CharAt(NewText.Length - 1) = "0" OR NewText.CharAt(NewText.Length - 1) = "") Then
If OldText.Length > NewText.Length Then
Return
End If
If (OldText.Length = 3) Then
txtDocumentNumber.Text = txtDocumentNumber.Text.SubString2(0, 3) & "." & NewText.Replace(txtDocumentNumber.Text.SubString2(0, 3), "")
Else If (OldText.Length = 7) Then
txtDocumentNumber.Text = txtDocumentNumber.Text.SubString2(0, 7) & "." & NewText.Replace(txtDocumentNumber.Text.SubString2(0, 7), "")
Else If (OldText.Length = 11) Then
txtDocumentNumber.Text = txtDocumentNumber.Text.SubString2(0, 11) & "-" & NewText.Replace(txtDocumentNumber.Text.SubString2(0, 11), "")
Else If (NewText.Length > 14) Then
txtDocumentNumber.Text = txtDocumentNumber.Text.SubString2(0, 14)
End If
Else
txtDocumentNumber.Text = OldText
End If
End If
Log("txtDocumentNumber " & txtDocumentNumber.Text)
End Sub