Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Semi-Validate Email

Status
Not open for further replies.

Vec

IS-IT--Management
Jan 29, 2002
418
0
0
US
How do I look at a text box and make sure it contains only one "@" and at least one "." (some emails have more than one "." but all emails can only contain one "@")

Pseudo code:

Look at Text1
If it contains only 1 "@" and at least 1 "." then
MsgBox "Valid"
If it does not meet both of these criteria then
MsgBox "Not Valid"
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
-- Rich Cook.

teklogo.gif

 
Vec, here is a function I use to validate email addresses.

Public Function VaildEmail(txtText As TextBox) As Boolean

Dim intX As Integer '### Count Integer

Dim intY As Integer '### @ Character
Dim intZ As Integer '### . Character
Dim intW As Integer '### Count of @ Character

Dim strA As String '### tmp String

Dim strEmail As String

If txtText.Text = "" Then
VaildEmail = True
Exit Function
Else
VaildEmail = False
End If

strEmail = Trim(txtText.Text)

intW = 0

For intX = 1 To Len(strEmail)
strA = Mid(strEmail, intX, 1)
If strA = "@" Then
intY = intX
intW = intW + 1
ElseIf strA = "." Then
intZ = intX
End If
Next intX

'### If @ is not the first character
'### if @ is not followed immediately by a .
'### If . is not the last character
'### If not more than one @

If (intY <> 1) And (intZ > intY + 1) And (intZ < Len(strEmail) And (intW = 1)) Then VaildEmail = True

End Function

Good Luck
 
Looks great, how do I put it into a command button, or even use it for that matter? &quot;Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.&quot;
-- Rich Cook.

teklogo.gif

 
Try this :

Private Sub Command1_Click

If txtEmail.text <> &quot;&quot; then
if VaildEmail(txtEmail) = True then
msgbox &quot;Valid Email&quot;
Else
msgbox &quot;Email is invalid&quot;
End if
End if

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top