Do you want the focus to remain on tf1 until the input is valid?
Full code:
B4X:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private tf1 As TextField
Private tf2 As TextField
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
MainForm.Show
tf1.Id="1"
tf2.Id="2"
End Sub
Sub tf1_FocusChanged (HasFocus As Boolean)
If HasFocus = False Then
If tf1.Text.ToUpperCase="NO" Then
Sleep(100)
tf1.RequestFocus
End If
End If
End Sub
There is a warning message in debug mode. Ignore it.