Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2006, 09:32 AM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default email validation function

Hi,
I need an email validation function in asp.net.
I can use custom validation but there is a problem.
I have a textbx that user enters email separated with commas and I don't know how to validate each email
that is the asp code
strTo=request.form("to")
strEmails=split(strTo,",")
For each strTo in strEmails
if IsEmail(strTo)="True" then
%>
<table class=Err align=center>
    <tr>
    <td class=font1><%response.write email & " " & "<b>" & strTo & "</b>" & emailNotValid%></td>
    </tr>
</table>
<br>
<%
response.end
end if
next


 
Old August 17th, 2006, 11:39 AM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Couldn't you put the email addresses into an array and check them separately?

Dim EmailAddresses As Array = Split(Request("EmailAddresses"), ",")
For i = 0 to Ubound(EmailAddresses)
If not CheckEmailFunction(EmailAddresses(i)) Then
Response.Write(EmailAddresses(i) & "<br />")
Next

 
Old August 17th, 2006, 04:54 PM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok.thanks rstelma
now can you give me asp.net email function
I USED before the asp version:
Private Function IsEmail(byVal mailaddress)
    Dim tmp, x, y, bErr, tmp2, objReg
    Dim objMatch, z, i
    bErr = False
    tmp = Trim( mailaddress )
    tmp = CStr( mailaddress )
    if len(tmp) < 6 then
        IsEmail = "True"
        Exit Function
    end if
    If instr(tmp, "@") then
        x = instr(tmp, "@")
        y = instr(x + 1, tmp, "@")
        'On Error Resume Next
        y = CLng(y)
        If Err Then bErr = True Else bErr = False
        On Error GoTo 0
        If bErr Then
            IsEmail = "True"
            Exit Function
        End If
        if y <> 0 then
            IsEmail = "True"
            Exit Function
        end if
    Else
        IsEmail = "True"
        Exit Function
    End If
    If InStr( Left( tmp, CLng(x) ), "." ) Then
        IsEmail = "gg"
        Exit Function
    Else
        tmp2 = Right( tmp, Len(tmp) - CLng(x) )
        If InStr( tmp2, "." ) Then
            Set objReg = New RegExp
            With objReg
                .Global = True
                .IgnoreCase = True
                .Pattern = "[A-Z]|[0-9]"
                Set objMatch = .Execute(tmp2)
            End With
            If objMatch.Count = 0 then
                IsEmail = "True"
                Exit Function
            End If
            Set objMatch = Nothing
            Set objReg = Nothing
        Else
            IsEmail = "True"
            Exit Function
        End If
    End If
    z = InStr( tmp, "." )
    tmp2 = Right( tmp, Len(tmp) - z )
    Set objReg = New RegExp
    With objReg
        .Global = True
        .IgnoreCase = True
        .Pattern = "[A-Z][A-Z]"
        Set objMatch = .Execute(tmp2)
    End With
    If objMatch.Count = 0 then
        IsEmail = "True"
        Exit Function
    End If
    Set objMatch = Nothing
    Set objReg = Nothing
    For i = 1 to Len(tmp)
        tmp2 = Mid( tmp, i, 1 )
        Select Case tmp2
            Case "(", ")", ";", ":", ",", "/", "'", chr(34), _
                 "~", "`", "!", "#", "$", "%", "^", "&", "*", _
                 "+", "=", "[", "]", "{", "}", "|", "\", "?", _
                 " ", "<", ">"
                IsEmail = "True"
                Exit Function
            Case Else
        End Select
    Next
    IsEmail = ""
End Function



 
Old August 17th, 2006, 05:30 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Here ya go.

    Function CheckEmail(ByVal Value As String) As Boolean
        Dim ex As Regex = New Regex("^[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]$")
        Return ex.Match(Value).Success
    End Function





Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple email validation (different format) kumiko Javascript 2 July 22nd, 2008 08:06 AM
email validation doesn't work in CreateUserWizard hertendreef ASP.NET 2.0 Professional 0 February 20th, 2008 01:20 PM
Email validation problem mattastic Javascript How-To 1 May 19th, 2005 01:10 AM
email validation check if it's correct? xristina Javascript 2 October 14th, 2004 01:51 PM
email validation tysta JSP Basics 3 June 23rd, 2003 12:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.