Android Question Regex Pattern in B4XFloatTextField (B4XDialog Custom)

asales

Expert
Licensed User
Longtime User
The B4XInputTemplate has a RegexPattern property, but I can only set and check one field.

Is possible to set a regex pattern to validate the input in B4XFloatTextField?

Or create a B4XInputTemplate with several input fields?

I have this in B4XDialog custom and would be nice to check the fields (date, time, value) and enable the OK button when the pattern matches.

dialog2.jpg
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You shouldn't use B4XInputTemplate for this. Create a custom dialog. You will have full control over its behavior.

A B4J example is attached.

Main code:
B4X:
Sub Button1_Click
   Dim p As B4XView = xui.CreatePanel("")
   p.SetLayoutAnimated(0, 0, 0, 300dip, 200dip)
   p.LoadLayout("MyDialog")
   Dialog.PutAtTop = True
   Dim rs As ResumableSub = Dialog.ShowCustom(p, "OK", "", "CANCEL")
   txtFirstName.TextField.RequestFocus
   IsDialogValid(txtFirstName.Text, txtLastName.Text)
   Wait For (rs) Complete (Result As Int)
   Dialog.PutAtTop = False
   If Result = xui.DialogResponse_Positive Then
       Dialog.Show($"Hello ${txtFirstName.Text} ${txtLastName.Text}"$, "OK", "", "")
   End If
End Sub

Private Sub IsDialogValid (FirstName As String, LastName As String)
   Dim ok As B4XView = Dialog.GetButton(xui.DialogResponse_Positive)
   If FirstName.Length > 0 And LastName.Length > 0 Then
       ok.Enabled = True
   Else
       ok.Enabled = False
   End If
End Sub

Sub txtFirstName_TextChanged (Old As String, New As String)
   IsDialogValid(New, txtLastName.Text)
End Sub

Sub txtLastName_TextChanged (Old As String, New As String)
   IsDialogValid(txtFirstName.Text, New)
End Sub
 

Attachments

  • 1.zip
    3.5 KB · Views: 367
Upvote 0
Top