Valid Email ID , this program is designed to find out whether user input is like a email id or other.
How to valid email id with vb.net.
Working with Vb.net 2012 its easy and quite tough to handle the code.
This code work whether in vb.net or with vb 6.0. It is simple and combination of all codes like variables loop and conditions.
First of all Open the program. And place label ,textbox and command button to the form.
Provide name of the controls.
Textbox as txtbox
command as btnok continue.................................
then you must visualize the email id to be.
Email Id is like abcd@gmail.com
It means there is @ in the middle , . dot after @ with some letters or number then some letters.
It is formatted in mind to apply.
Here is a code to apply in btnok code.
---------------------------------------------------------------------------------------------------
On Error GoTo err
Dim stra, strb, strc, strd As String
Dim i, j As Integer
strb = txtbox.Text
stra = "!#$%^&*():;'<>,+="
If txtbox.Text = "" Then
MsgBox("Please Input Email-ID")
Exit Sub
Else
For i = 1 To Len(strb)
strc = Mid(strb, i, 1)
For j = 1 To Len(strb)
strd = Mid(stra, j, 1)
If strc = strd Then
MsgBox(" Invalid Character !!!!!!", vbCritical + vbInformation)
txtbox.Focus()
txtbox.BackColor = Color.Brown
Exit Sub
End If
Next
Next
Dim k, l, m As Integer
Dim strrat, strdot As String
For k = 1 To Len(strb)
strrat = Mid(strb, k, 1)
If strrat = "@" Then
For l = k To Len(strb)
strdot = Mid(strb, l + 1, 1)
If strdot = "." Then
If (Len(strb) - l) >= 3 Then
txtbox.BackColor = Color.White
MsgBox("Valid Email Address")
Exit Sub
Else
MsgBox("Invalid Email ID !!!!!!", vbCritical)
txtbox.Focus()
txtbox.BackColor = Color.Brown
Exit Sub
End If
Next
End If
Next
End If
MsgBox("Invalid Email ID !!!!!!", vbCritical)
txtbox.Focus()
Exit Sub
err:
MsgBox(Err.Description)
End Sub
-------------------------------------------------------------------
Simple description about code.
In the first line.. i have checked whether there is error in the command ,if error then describe to last line.
In the second and third line i have assigned variables necessary to check the input data.
Then i have checked whether the textbox is empty or filled with. If empty then error message
MsgBox("Please Input Email-ID")
Then i have checked the invalid characters using loop.
Using loop if condition ,if true then go to the next loop of finding @.
After then checking . dot and letters with. then
all format will be checked.
Lets see by running the project.
Press buttons
Results
again,
Results
Thank You.
Please comment if any questions.
No comments:
Post a Comment