### Numeric Input Field

A numeric TextField using IsNumber to validate and show visual validation by either red or transparent border.
See also Category Number.
`Sub Process_Globals
Private TextField1 As TextField
...
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Main")
MainForm.SetFormStyle("UTILITY")
MainForm.Title = "B4J HowTo Numeric Field"
MainForm.Show
End Sub`
`Sub TextField1_TextChanged (Old As String, New As String)
' Empty field - reset styles
If New.Length = 0 Then
CSSUtils.SetBorder(Sender, 2, fx.Colors.Transparent, 2)
CSSUtils.SetStyleProperty(TextField1, "-fx-text-fill", "black")
Return
End If
' Digital comma is allowed - but needs to be replaced by dot.
If New.Contains(",") Then New = New.Replace(",", ".")
' Invalid input
If Not(IsNumber(New)) Then
CSSUtils.SetBorder(Sender, 2, fx.Colors.Red, 2)
CSSUtils.SetStyleProperty(TextField1, "-fx-text-fill", "red")
Else
' Valid input
CSSUtils.SetBorder(Sender, 2, fx.Colors.Transparent, 2)
CSSUtils.SetStyleProperty(TextField1, "-fx-text-fill", "black")
End If
End Sub`

Changed: 2018-04-29 09:46, Category: TextField, File: T6C262M1942.htm, ID: 1942