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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email validation problem... wierd..

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
None of these work... why not??
Code:
<%

EmailAdd = Request.Form(&quot;email_address&quot;)

If NOT InStr(EmailAdd, &quot;@&quot;) = 1 then  
'# If less or more then 1 its an invalid email	
ErrEmail = True
End If

If InStr(EmailAdd, &quot;@&quot;) <> 1 then  
'# If less or more then 1 its an invalid email	
ErrEmail = True
End If


%>
 
How about
Code:
If inStr(EmailAdd,&quot;@&quot;) < 1 Then
   Response.Write &quot;You tricky person you, thats not an email address!&quot;
End If

Or

If inStr(EmailAdd,&quot;@&quot;) > 0 Then
   response.Write &quot;Thats really your email address? No kidding, how nifty.&quot;
End if

As is probably obvious, the first should an error case, the @ didn't show up, it's not an email. The second proves that it does have an @ symbol so it should be an email address.

-Tarwn
Of course, it is also pretty obvious that I didn't sleap much last night.
 
I got this one to work:

If inStr(EmailAdd,&quot;@&quot;) < 1 Then
Response.Write &quot;You tricky person you, thats not an email address!&quot;
End If

But if you put the above one and the following one it doesnt work...

If inStr(EmailAdd,&quot;@&quot;) > 2 Then
Response.Write &quot;You can't have more then 1 @ symbol in your email!&quot;

End If
 
Ah, i See the problem now. inStr(string,character) returns the position of the first match of the character in the string. inStr returns 0 for not found, otherwise position of the first match.
inStr: not is it in the string, but where in the string is it
-Tarwn
 
I always forget that InStr only tells you the position, and its not a count.. hmm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top