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!

email verification- problem with instr() function 1

Status
Not open for further replies.

KingElvis

Programmer
Jan 28, 2004
39
0
0
IL
I'm using the simple code below to verify an email address. However, the line that reads
If InStr(1, email, ".", 1) < 4 Then
returns emailOK = 1.

Is there a syntax problem? Seeing that I am looking for the character "." I am not sure if the 'compare' parameter of inStr() be 1 (textual comparison) or 0 (binary comparison)? Does it make a difference?


Dim emailOK
emailOK = 0
If Len(email) < 6 Then
emailOK = 1
End If
If InStr(1, email, "@", 1) < 2 Then
emailOK = 1
Else
If InStr(1, email, ".", 1) < 4 Then
emailOK = 1
End If
End If
If emailOK <> 0 then
response.write "Incorrect Email..."
End If
 
I lost track of the logic in there somewhere and red on blue is not great to read code from ( hint; use the code markup tags )

Code:
if (instr(strEmail,"@") < 2 or instr(strEmail,".") = 0) then emailOK = 1

will work ok but it won't check if there is a dot after the @ symbol
so a more complete function I use is this
Code:
function CheckEmail(strEmail)
dim temp
temp = false
if len(strEmail) > 6 then temp = true
	if temp then 
		if (instr(strEmail,"@") < 2 or instr(strEmail,".") = 0) then
			temp = false
		else
		if instr(instr(strEmail,"@"),strEmail,".") = 0 then
			temp = false
		end if		
		end if
	end if
CheckEmail = temp 
end function

you could of course use a regexp to validate. it would give a little extra syntax checking.

Code:
function CheckMail(strEmail)
 dim objRE
  Set objRE = New RegExp
  objRE.Pattern = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
  objRE.IgnoreCase = true
  CheckMail = objRE.Test(strEmail)
set objRE = Nothing
end function
and no I'm not going to try to explain it [lol]


Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top