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 !




How to validate an email address


Posted Date: 04 May 2008    Resource Type: Code Snippets    Category: Validations

Posted By: Rekha        Member Level: Gold
Rating:     Points: 15



This sample code snippet helps to validate an email address using regular expressions. Returns true is the address provided is true, otherwise returns false

public bool IsValidEmail(string email)
{
string pat = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.
(com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|[a-zA-Z]{2})$";
Regex check = new Regex(pat,RegexOptions.IgnorePatternWhitespace);
bool valid = false;

if (string.IsNullOrEmpty(email))
{
valid = false;
}
else
{
valid = check.IsMatch(email);
}
return valid;
}




Responses

Author: asmita    05 May 2008Member Level: Bronze   Points : 2
Good Snippet...Really helpful...Thanks..!!


Author: vijayapriya    05 May 2008Member Level: Silver   Points : 2
public bool isValidEmail(string inputEmail)
{
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
if (re.IsMatch(inputEmail))
return (true);
else
return (false);
}


Author: andy robarts    05 May 2008Member Level: Gold   Points : 2
http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx


Author: venkat kamal    05 May 2008Member Level: Gold   Points : 2
really good snippet and its nice.....


Author: Raj Kumar Prajapati    27 Aug 2008Member Level: Bronze   Points : 0
Good Snippet...Really helpful...Thanks..!!
THANKS RAJ PRAJAPATI


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: How to validate an IP address from 1.0.0.0 to 255.255.255.255
Previous Resource: How to check and see if a string is all uppercase in c#
Return to Discussion Resource Index
Post New Resource
Category: Validations


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

it help desk

Contact Us    Privacy Policy    Terms Of Use