Skip to main content

Posts

Showing posts from August, 2011

Email Validation in .Net

Function for Email Validation 1. It allows max 5 dots(.) including .com and max 5 hyphen(-) 2. Only 4 Special Characters allowed are (- _ . @) 3. @ character is allowed only once and is mandatory. private bool email() {       string pattern = @"^([a-zA-Z0-9])+([\w_\.\-]([a-zA-Z0-9])*[a-zA-Z0-9])*@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}$)";       System.Text.RegularExpressions.Match match = Regex.Match(textBox1.Text.Trim(), pattern, RegexOptions.IgnoreCase);       if ((match.Success))       {             string[] words = Regex.Split(textBox1.Text.Trim(), "@");             string word1 = words[1].ToString();             int dotCount = word1.Count(f = > f == '.');             int hyfenCount = word1.Count(f = > f == '-');             if (!(dotCount < 6))             {                   MessageBox.Show("Invalid Email-id");                   return false;             }             else if (!(h