C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Validate an email address


Posted Date: 10 Mar 2004    Resource Type: Articles    Category: .NET Framework
Author: Satheesh SugumaranMember Level: Gold    
Rating: Points: 7




Function ChkValidEmail(ByVal Value As String, Optional ByVal MaxLength As _
Integer = 255, Optional ByVal IsRequired As Boolean = True) As Boolean
If Value Is Nothing OrElse Value.Length = 0 Then
' rule out the null string case
Return Not IsRequired
ElseIf Value.Length > MaxLength Then
' rule out values that are longer than allowed
Return False
End If

' search invalid chars
If Not System.Text.RegularExpressions.Regex.IsMatch(Value, _
"^[-A-Za-z0-9_@.]+$") Then Return False

' search the @ char
Dim i As Integer = Value.IndexOf("@"c)
' there must be at least three chars after the @
If i <= 0 Or i >= Value.Length - 3 Then Return False
' ensure there is only one @ char
If Value.IndexOf("@"c, i + 1) >= 0 Then Return False

' check that the domain portion contains at least one dot
Dim j As Integer = Value.LastIndexOf("."c)
' it can't be before or immediately after the @ char
If j < 0 Or j <= i + 1 Then Return False

' if we get here the address if validated
Return True
End Function






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Check whether an object is storing a numeric value
Previous Resource: How to add a mulitple entries in listbox using an add button from another listbox and then remove th
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use