Please help how can i count number of dots i have in my email please help
B4X:
Dim arrName() As String=Regex.Split(".",Name)
Log($"Number of commas: ${arrName.Length-1}"$)
If arrName.Length-1 >1 Then
MsgboxAsync("You have more than one dot in our Email please remove it thanks","More Dots Detected")
Return
End If
I have not tested this, but it should count the number of "." characters in a string ...
B4X:
Sub countDots(text As String) As Int
Dim n As Int = 0
Dim p As Int = text.IndexOf(".")
Do While (p > -1)
n = n + 1
text = text.SubString(p + 1)
p = text.IndexOf(".")
Loop
Return n
End Sub
If arrName.Length - arrName.Replace(".", "").Length > 1 Then
MsgboxAsync("You have more than one dot in our Email please remove it thanks","More Dots Detected")
Return
End If
You code would have worked if you escaped the dot. See the code below I corrected for you. This is not better than what Brian or Angel offered. It is just another way to stay with your line of thinking:
B4X:
Dim name As String =" I decided. to check .out this thread. because it. has a lot. of unnecessary .dots"
Dim arrName() As String=Regex.Split("\.",name) '<-----
Log($"Number of dots: ${arrName.Length-1}"$) 'displays 6
If arrName.Length-1 >1 Then
MsgboxAsync("You have more than one dot in our Email please remove it thanks","More Dots Detected")
Return
End If
SubName: Validate a users email address format using a regular expression. Description: You can use the following code to validate that a user has entered a correctly formatted email address. Characters like "@ , > = .. etc" are checked and the email address format is validated via the regular...