Check valid email address - client/server
Lately I needed to create a webpage where an input field was needed where multiple email addresses could be entered, separated with commas. In this particular case, I only provided validation on server-side using the Regex class (namespace System.Text.RegularExpressions).
public void DoValidationForEmails(string inputString)
{
//inputString contains all email addresses, separated with commas
string separator = ",";
string[] allEmails = inputString.Split(separator.ToCharArray());
//Regular Expression for validating email addresses
Regex regularExpression = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
foreach (string emailAddress in allEmails)
{
if (regularExpression.IsMatch(emailAddress))
{
//Valid email address
}
else
{
//Invalid email address
}
}
}
Anyone already done this on client-side as well?
Labels: ASP.NET 2.0