E-Mail and Access Code Verificationin VB.Net
Public Class form1
Public Function ValidateEmailId(ByVal emailId As String) As Integer
Dim rEMail As New System.Text.RegularExpressions.Regex("^[a-zA-Z][\
w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")
If emailId.Length > 0 Then
If Not rEMail.IsMatch(emailId) Then
Return 0
Else
Return 1
End If
End If
Return 2
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim status As Integer = ValidateEmailId(TextBox1.Text)
If status = 0 Then
MessageBox.Show("E-Mail Id expected", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
ElseIf status = 1 Then
If Char.IsLetter(TextBox2.Text) = False Or (Len(TextBox2.Text) < 3) Or (Len(TextBox2.Text) > 3) Then
MsgBox("Invalid Access Code.", MsgBoxStyle.Information = MsgBoxStyle.OkCancel, "Error Information")
ElseIf Char.IsLetter(TextBox2.Text) = True Or (Len(TextBox2.Text) = 3) Then
MessageBox.Show("Thanks for providing a valid E-mail Id. ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
ElseIf status = 2 Then
MessageBox.Show("Please enter E-mail Id", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
End Class
End Class
Comments
Post a Comment