ATMLCommonLibrary.controls.validators.RegularExpressionValidator.Validate C# (CSharp) Method

Validate() protected method

protected Validate ( ) : bool
return bool
        protected override bool Validate()
        {
            bool valid = true;
            if (IsEnabled && ControlToValidate.Enabled && !string.IsNullOrWhiteSpace(_regularExpression ) )
            {
                // Is valid if different than initial value,
                // which is not necessarily an empty string
                Regex regex = new Regex(_regularExpression);
                string controlValue = ControlToValidate.Text.Trim();
                string initialValue;
                if (_initialValue == null) initialValue = "";
                else initialValue = _initialValue.Trim();
                _isValid = regex.Match(controlValue).Success;
                // Display an error if ControlToValidate is invalid
                string errorMessage = "";
                if (!_isValid)
                {
                    errorMessage = _errorMessage;
                    if (_icon != null)
                        ErrorProvider.Icon = _icon;
                    valid = false;
                    if (ControlToValidate is ATMLControl)
                        ((ATMLControl)ControlToValidate).HasErrors = true;
                }
                ErrorProvider.SetError(_controlToValidate, errorMessage);
            }
            return valid;
        }
RegularExpressionValidator