### Validate Text entered

To accept only Alphabetical or Decimal numbers, use the TextField TextChanged event.
If the text contains a non-numeric character then delete it.
Example Code Alpha Characters
' Accept alpha characters only
`Sub IsAlpha(s As String) As Boolean 'ignore
Return Regex.IsMatch("[A-Za-z]+", s)
End Sub`
' Handle TextField change. Show in a label input result
`Sub TextField1_TextChanged (Old As String, New As String)
' Empty field - reset styles
If New.Length = 0 Then
Label2.Text = $"Field is empty"$
CSSUtils.SetBorder(Sender, 2, fx.Colors.Transparent, 2)
CSSUtils.SetStyleProperty(Label2, "-fx-text-fill", "black")
Return
End If
' Check for aplha chars only
' Invalid input
If Not(IsAlpha(New)) Then
Label2.Text = $"Non alpha character entered."$
CSSUtils.SetBorder(Sender, 2, fx.Colors.Red, 2)
CSSUtils.SetStyleProperty(Label2, "-fx-text-fill", "red")
Else
' Valid input
Label2.Text = $"Valid alpha character entered."$
CSSUtils.SetBorder(Sender, 2, fx.Colors.Transparent, 2)
CSSUtils.SetStyleProperty(Label2, "-fx-text-fill", "black")
End If
End Sub`
Example Code (old version without Regex)
`Sub keyboard_TextChanged (Old As String, New As String)
Dim ch As String
Dim allowedchar As String
allowedchar = "0123456789+*/-. ch"
ch = keyboard.Text
If allowedchar.Contains(ch) Then
If ch = 0 Then b0_Action
If ch = 1 OR ch = 2 OR ch = 3 OR ch = 4 OR ch = 5 OR ch = 6 OR ch = 7 OR ch = 8 OR ch = 9 Then
btn.Text = ch
keyboardinput = True
b_Action
End If
If ch = "+" Then bpl_Action
If ch = "/" Then bd_Action
If ch = "-" Then bmin_Action
If ch = "*" Then bmal_Action
If ch = "." Then bp_Action
If ch = "c" Then bc_Action
If ch = " " Then bg_Action
If ch = "h" Then his_Action
End If
keyboard.Text = ""
keyboard.RequestFocus
End Sub`

Changed: , Category: TextField, File: T6C262M1949.htm, ID: 1949