Ciduletz1983
Active member
How can i test a text from a textbox containing only one "@" ?
Dim str As String = myTextBox.Text
Dim firstIndex As Integer = str.IndexOf("@"c)
Dim lastIndex As Integer = str.LastIndexOf("@"c)
If firstIndex <> -1 AndAlso firstIndex <> lastIndex Then
'There is one and only one "@" in the TextBox.
End If
It seems u know all the properties of a string variable. This code is too advanced for me right now. In the future it won`t be. Thx anyway.
How can i test a text from a textbox containing only one "@" ?
If "@".Equals(textbox1.Text) Then
'the box contains one @
Else
'the box contains soemthing else
Endif
If Me.emailText.Text.Trim() = String.Empty OrElse _
Regex.IsMatch(Me.emailText.Text, My.Resources.EmailRegexPatternString) Then
Me.errorIndicator.SetError(Me.emailText, Nothing)
Else
Me.errorIndicator.SetError(Me.emailText, My.Resources.InvalidEmailErrorString)
End If
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] TextBox1.Text.Contains([/SIZE][SIZE=2][COLOR=#800000]"@"[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2] MsgBox([/SIZE][SIZE=2][COLOR=#800000]"Yes, TextBox1 Contains '@'"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2] MsgBox([/SIZE][SIZE=2][COLOR=#800000]"No, TextBox1 not Contains '@'"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[/COLOR][/SIZE]
Nice try but the question was how to determine whether the TextBox contains ONLY one "@". That code tests for the presence of one OR MORE "@"sHi,
VB.NET:[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] TextBox1.Text.Contains([/SIZE][SIZE=2][COLOR=#800000]"@"[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE] [SIZE=2] MsgBox([/SIZE][SIZE=2][COLOR=#800000]"Yes, TextBox1 Contains '@'"[/COLOR][/SIZE][SIZE=2])[/SIZE] [SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE] [SIZE=2] MsgBox([/SIZE][SIZE=2][COLOR=#800000]"No, TextBox1 not Contains '@'"[/COLOR][/SIZE][SIZE=2])[/SIZE] [SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE] [/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] n, n1 [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] n = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] Len(TextBox1.Text) - 1[/SIZE]
[SIZE=2][COLOR=#0000ff] If[/COLOR][/SIZE][SIZE=2] (TextBox1.Text(n)) = [/SIZE][SIZE=2][COLOR=#800000]"@" [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2] n1 += 1[/SIZE]
[SIZE=2][COLOR=#0000ff] End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#800000]"TextBox1 Contains "[/COLOR][/SIZE][SIZE=2] & n1)[/SIZE]