Sunday, July 22, 2007

Dot Net Codes-Email Address Validation

Vb.net Code to validate an e-mail address specified in a text box

Public Shared Function email_validation1(ByVal str As String) As Boolean
If Left(str, 1) = "@" Then
rsMessageBox("@ Could not be the First Character")
Return False
End If
If Right(str, 1) = "@" Then
rsMessageBox("@ Could not be the Last Character")
Return False
End If
If Right(str, 1) = "." Then
rsMessageBox("Mail id can not ends with dot")
Return False
End If
If InStr(str, "@") = 0 Then
rsMessageBox("There is no @ symbol")
Return False
End If
If InStr(InStr(str, "@") + 1, str, "@") <> 0 Then
rsMessageBox("There are more than one @ symbol")
Return False
End If
If InStr(str, ".") = 0 Then
rsMessageBox("There is no Dot")
Return False
End If
If InStr(str, " ") <> 0 Then
rsMessageBox("There is a blank space")
Return False
End If
If Abs(InStr(str, "@") - InStr(str, ".")) = 1 Then
rsMessageBox("Dot and @ cannot be Adjascent")
Return False
End If
Return True
End Function

No comments: