There is also a way to capitalize the first letter of each of the words
Log("*** Fixed format First Middle Last ***")
Log(ToMixCase(B4XFloatTextField1.Text))
If Regex.IsMatch("^([\w-.]+)\h*(.+)\h*\b(\w+)$", B4XFloatTextField1.Text) Then
Dim Matcher1 As Matcher = Regex.Matcher("^([\w-.]+)\h*(.+)\h*\b(\w+)$", B4XFloatTextField1.Text)
Matcher1.Find
Log("First: " & ToMixCase(Matcher1.Group(1)))
Log("Middle: " & ToMixCase(Matcher1.Group(2)))
Log("Last: " & ToMixCase(Matcher1.Group(3)))
End If
Public Sub ToMixCase(Entry As String) As String
Dim sb As StringBuilder
Dim I As Int
Entry = Entry.ToLowerCase
sb.Initialize
Dim m As Matcher =...
Public Sub EdiText1_EnterPressed
Dim Text1 As EditText = Sender
If Text1.Text.Trim.IndexOf(" ")>-1 Then
' accept
' focus to nex view
Else
' wrong
ToastMessageShow("Ahi ahi ahi",True)
Text1.RequestFocus
End If
End Sub
Public Sub EdiText1_EnterPressed
Dim Text1 As EditText = Sender
If Text1.Text.Trim.Contains("Isaac Donkor,") Or Text1.Text.Trim.Contains("Michael John Smith") Or Text1.Text.Trim.Contains("William McAlpine") Then
' accept
' focus to nex view
Else
' wrong
ToastMessageShow("Ahi ahi ahi",True)
Text1.RequestFocus
End If
End Sub
Thank you I will try if this works.I guess by TextField in B4A I meant edittext....
B4X:Public Sub EdiText1_EnterPressed Dim Text1 As EditText = Sender If Text1.Text.Trim.IndexOf(" ")>-1 Then ' accept ' focus to nex view Else ' wrong ToastMessageShow("Ahi ahi ahi",True) Text1.RequestFocus End If End Sub
Please, what I was trying to emphasize on was the format. {First name} {Lastname} thus the Isaac Donkor
Private Sub B4XFloatTextField1_EnterPressed
Dim Matcher1 As Matcher = Regex.Matcher("([^\s]+)", B4XFloatTextField1.Text)
Do While Matcher1.Find
Log("Found: " & Matcher1.Match)
Loop
End Sub
Private Sub B4XFloatTextField1_EnterPressed
Log("*** Free format of names and surnames ***")
Dim Matcher1 As Matcher = Regex.Matcher("([^\s]+)", B4XFloatTextField1.Text)
Do While Matcher1.Find
Log("Found: " & Matcher1.Match)
Loop
Log("*** Fixed format First Middle Last ***")
If Regex.IsMatch("^([\w-.]+)\h*(.+)\h*\b(\w+)$", B4XFloatTextField1.Text) Then
Dim Matcher1 As Matcher = Regex.Matcher("^([\w-.]+)\h*(.+)\h*\b(\w+)$", B4XFloatTextField1.Text)
Matcher1.Find
Log("First: " & Matcher1.Group(1))
Log("Middle: " & Matcher1.Group(2))
Log("Last: " & Matcher1.Group(3))
End If
End Sub
other
This won't work for Norah Mary O'DonnellLog("*** Fixed format First Middle Last ***")
You can add that in groups the characters (- or ') are part of the first or last name.This won't work for Norah Mary O'Donnell
The free format will probably be more suitable in that case.
There is also a way to capitalize the first letter of each of the words via RegeX that escapes me,, although a sub can be built to do it.
There is also a way to capitalize the first letter of each of the words
Log("*** Fixed format First Middle Last ***")
Log(ToMixCase(B4XFloatTextField1.Text))
If Regex.IsMatch("^([\w-.]+)\h*(.+)\h*\b(\w+)$", B4XFloatTextField1.Text) Then
Dim Matcher1 As Matcher = Regex.Matcher("^([\w-.]+)\h*(.+)\h*\b(\w+)$", B4XFloatTextField1.Text)
Matcher1.Find
Log("First: " & ToMixCase(Matcher1.Group(1)))
Log("Middle: " & ToMixCase(Matcher1.Group(2)))
Log("Last: " & ToMixCase(Matcher1.Group(3)))
End If
Public Sub ToMixCase(Entry As String) As String
Dim sb As StringBuilder
Dim I As Int
Entry = Entry.ToLowerCase
sb.Initialize
Dim m As Matcher = Regex.Matcher("(^\w)|(\s\w)", Entry)
Do While m.Find
If m.Match.Length > 1 Then
sb.Append(Entry.SubString2(I, m.GetStart(0) + 1))
sb.Append(m.Match.SubString(1).ToUpperCase)
Else
sb.Append(Entry.SubString2(I, m.GetStart(0)))
sb.Append(m.Match.ToUpperCase)
End If
I = m.GetEnd(0)
Loop
If I < Entry.Length Then
sb.Append(Entry.SubString(I))
End If
Return sb.ToString
End Sub
This worked Great. Thank you.B4X:Log("*** Fixed format First Middle Last ***") Log(ToMixCase(B4XFloatTextField1.Text)) If Regex.IsMatch("^([\w-.]+)\h*(.+)\h*\b(\w+)$", B4XFloatTextField1.Text) Then Dim Matcher1 As Matcher = Regex.Matcher("^([\w-.]+)\h*(.+)\h*\b(\w+)$", B4XFloatTextField1.Text) Matcher1.Find Log("First: " & ToMixCase(Matcher1.Group(1))) Log("Middle: " & ToMixCase(Matcher1.Group(2))) Log("Last: " & ToMixCase(Matcher1.Group(3))) End If
B4X:Public Sub ToMixCase(Entry As String) As String Dim sb As StringBuilder Dim I As Int Entry = Entry.ToLowerCase sb.Initialize Dim m As Matcher = Regex.Matcher("(^\w)|(\s\w)", Entry) Do While m.Find If m.Match.Length > 1 Then sb.Append(Entry.SubString2(I, m.GetStart(0) + 1)) sb.Append(m.Match.SubString(1).ToUpperCase) Else sb.Append(Entry.SubString2(I, m.GetStart(0))) sb.Append(m.Match.ToUpperCase) End If I = m.GetEnd(0) Loop If I < Entry.Length Then sb.Append(Entry.SubString(I)) End If Return sb.ToString End Sub
View attachment 122706
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?