Validation controls in .NET 2.0 provide an easy-to-use mechanism for all common types of standard validation. You can drag and drop for instance the RegularExpressionValidator control
on your webform to determine whether the value of an input control matches a pattern defined by a regular expression
. Ideal to check a telephone number or an email address. This validation occurs by default on client-side and on server-side.
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)
//Valid email address
//Invalid email address
Anyone already done this on client-side as well?
Labels: ASP.NET 2.0