Android Question Entering an amount of money with B4XFloatTextField


Well-Known Member
Licensed User
Longtime User
I want to use such a view for users to enter an amount of money with two decimals, such 1.23, 12.34, 123.1, etc..

I've set the Keyboard type to Decimal already, and now I'm wondering what else I can do to enforce the decimal rule so that only valid values can be entered and I wouldn't have to do any validation afterwards.

Thank you in advance for your time!


Licensed User
Longtime User
enter an amount of money with two decimals
Maybe validate it for a max of 2 decimals as you suggested in your first post.
Sub B4XFloatTextField1_TextChanged (Old As String, New As String)
        If IsValid(New) =False Then
            Dim et As EditText =B4XFloatTextField1.TextField
            B4XFloatTextField1.TextField.SetColorAndBorder(Colors.cyan,10dip,Colors.Red,5dip)  'line optional
        End If        
End Sub
Sub IsValid(entry As Double) As Boolean  'allows only  digits with max 2 decimals
    Return Regex.IsMatch("^\d+\.?\d{0,2}$", entry) 'allows max 2 decimals
End Sub
Upvote 0