电子邮件验证格式VB /启用按钮

时间:2015-11-16 05:20:05

标签: vb.net if-statement drop-down-menu

早安所有:) 我非常基本的挣扎我知道,但我一直在调试它,它部分工作所以请帮助..我正在尝试做一些简单的验证..电子邮件验证的格式为abc @ domain .com,我想一个问题是它会显示messege等但它会进入下一个表单(我有两种形式)我希望它不继续并要求用户更改电子邮件输入以继续..

Protected Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles 

    TextBox3.TextChanged
    Dim chk As String = TextBox3.Text

    If chk.Contains("@") And chk.Contains(".") Then

    Else

        MsgBox("This is not a valid email. Please re-enter your email.")
    End If
End Sub

第二个问题我有一个下拉列表我在文本框下面,我想只在我选择" Sport&舞蹈"从下拉列表,否则我想要它,这虽然听起来容易和合乎逻辑,但它不适合我,我的代码在下面..所有的帮助非常感谢

        Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged

    If DropDownList1.Text.Contains("Sport & Dance") Then

        TextBox2.Enabled = False
    Else

        TextBox2.Enabled = True

    End If
End Sub





      Protected Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
    Dim chk As String = TextBox3.Text
    If chk.IndexOf("@", System.StringComparison.Ordinal) < 0 Then
        MsgBox("This is not a valid email. Please re-enter your email.")
    End If
End Sub

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged

    If DropDownList1.SelectedValue = ("Sports & Dance") Then

        TextBox2.Enabled = False
    Else

        TextBox2.Enabled = True

    End If

1 个答案:

答案 0 :(得分:1)

用于验证电子邮件地址..

   If chk.IndexOf("@", System.StringComparison.Ordinal) < 0 Then
       MsgBox("This is not a valid email. Please re-enter your email.")
   End If

为了您的下拉列表,

    If DropDownList1.SelectedValue = "Sport & Dance" Then

        TextBox2.Enabled = False
    Else

        TextBox2.Enabled = True

    End If