TextBoxValidationExtension

Mar 19, 2013 at 1:31 AM
I suggest to add the e-mail format to the validation formats:
        /// <summary>
        /// Text property needs to be an e-mail (using regular expression).
        /// </summary>
        Email=4,
        /// <summary>
        /// Text property needs to be an e-mail (using regular expression) and non-empty.
        /// </summary>
        NonEmptyEmail=5
and add this to Validate():
 var expectEmail = (format & ValidTextBoxFormats.Email) != 0;
            if (expectEmail && !isEmpty && !IsEmail())
            {
                MarkInvalid();
                return;
            }
            MarkValid();
and the function "IsEmail()"
 private bool IsEmail()
        {
            string pattern = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
            System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(pattern);
            return reg.Match(_textBox.Text).Success;
        }