Results 1 to 2 of 2

Thread: Loops and Lopps!

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Talking

    I am writing a simple code that checks 7 emails being submitted from a form. I am trying to use a loop to go through all the emails but my code only evaluates the first email submitted. Can anyone tell me the proper way to loop through the emails?

    Code:
    <!-- #INCLUDE FILE="validate.asp" -->
    <%
    
    	Dim MyEmail(6) 
    	Dim Count 
        
        MyEmail(0) = Request.Form("Y1")
        MyEmail(1) = Request.Form("A1")
        MyEmail(2) = Request.Form("A2")
        MyEmail(3) = Request.Form("A3")
        MyEmail(4) = Request.Form("A4")
        MyEmail(5) = Request.Form("A5")
        MyEmail(6) = Request.Form("A6")
        
        For Count = 0 to 6
          If IsValidEmail(MyEmail(Count)) = False Then
            Response.Redirect "EmailError.asp"
          Else
          	 Response.Redirect "Form.asp"
          End If
        Next
    now the function
    Code:
    <%
    Function IsValidEmail(email)
    
    	dim names, name, i, c
    
    	'Check for valid syntax in an email address.
    
    	IsValidEmail = true
    
    	names = Split(email, "@")
    	
    	if UBound(names) <> 1 then
    		IsValidEmail = false
    			exit function
    	end if
    	
    	for each name in names
    		if Len(name) <= 0 then
    			IsValidEmail = false
    				exit function
    		end if
    	
    	for i = 1 to Len(name)
    		c = Lcase(Mid(name, i, 1))
    			if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
    				IsValidEmail = false
    					exit function
    			end if
    	next
    	
    		if Left(name, 1) = "." or Right(name, 1) = "." then
    			IsValidEmail = false
    				exit function
    		end if
    	next
    	
    	if InStr(names(1), ".") <= 0 then
    		IsValidEmail = false
    			exit function
    	end if
    	
    	i = Len(names(1)) - InStrRev(names(1), ".")
    		if i <> 2 and i <> 3 then
    			IsValidEmail = false
    				exit function
    		end if
    		
    	if InStr(email, "..") > 0 then
    		IsValidEmail = false
    	end if
    
    	end function
    
    %>

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    it only checks the first one because of the redirect
    Mark
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width