Example #1
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var str = value as string;

            if (string.IsNullOrEmpty(str) || RegExValidation.IsAccountNumberValid(str))
            {
                return(ValidationResult.Success);
            }
            return(new ValidationResult(ErrorMessageString));
        }
Example #2
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var name = value as string;

            if (string.IsNullOrEmpty(name))
            {
                return(ValidationResult.Success);
            }
            return(RegExValidation.IsEmailValid(name) ? ValidationResult.Success : new ValidationResult(ErrorMessageString));
        }
Example #3
0
        public void Update_GivenMatchedPattern_ItUpdateItSelfToValidValidation()
        {
            // Arrange
            var groupName = "Name";
            var pattern   = "^[A-Za-z]+$";
            var target    = "Hugo";

            var validation =
                new RegExValidation(groupName, pattern);

            // Act
            var result = validation.Update(target);

            // Assert
            result.ShouldBe(validation);
            result.IsValid.ShouldBeTrue();
            result.Failures.ShouldBeEmpty();
        }
Example #4
0
        public void Update_GivenUnMatchedPattern_ItUpdateItSelfToAnInvalidValidation()
        {
            // Arrange
            var groupName       = "Name";
            var pattern         = "^[A-Za-z]+$";
            var target          = "HUgo*9)82";
            var defaultSeverity = 1;
            var defaultMessage  = "Name is not valid";

            var validation =
                new RegExValidation(groupName, pattern, target);

            // Act
            var result = validation.Update();

            // Assert
            result.ShouldBe(validation);
            result.IsValid.ShouldBeFalse();
            result.Failures.Count.ShouldBe(1);
            result.Failures.Single().Message.ShouldBe(defaultMessage);
            result.Failures.Single().GroupName.ShouldBe(groupName);
            result.Failures.Single().Severity.ShouldBe(defaultSeverity);
        }
        private bool ValidateSubmission()
        {
            try
            {
                //if (txtStationName.Text.Length < 5)
                //{
                //    MessageBox.Show(@"Station Name is required and must be more than 5 character long", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                //    return false;
                //}
                if (txtStationKey.Text == "")
                {
                    MessageBox.Show(@"Station ID is required", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return(false);
                }

                if (txtSurname.Text.Length < 3)
                {
                    MessageBox.Show(@"Kindly provide the Administrator's Surname", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return(false);
                }
                if (txtFirstName.Text.Length < 3)
                {
                    MessageBox.Show(@"Kindly provide the Administrator's First Name", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return(false);
                }

                if (txtUsername.Text.Length < 8)
                {
                    MessageBox.Show(@"Kindly provide the Administrator's Username", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return(false);
                }
                if (txtPassword.Text.Length != 8)
                {
                    MessageBox.Show(@"Invalid Administrator's login Password. Password must be exactly 8 character long: 6 number digits and 2 special characters", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return(false);
                }

                if (txtPassword.Text.Trim() != txtConfirmPassword.Text.Trim())
                {
                    MessageBox.Show(@"Password & Confirm Password must match", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return(false);
                }

                if (txtAdminAddress.Text.Length < 10)
                {
                    MessageBox.Show(@"Invalid / Admin Residential Address", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return(false);
                }
                if (txtAdminMobileNo.Text.Length < 7)
                {
                    MessageBox.Show(@"Kindly provide Admin's Mobile Number", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return(false);
                }
                //if (!GSMHelper.ValidateMobileNumber(txtAdminMobileNo.Text))
                //{
                //    MessageBox.Show(@"Invalid Admin Mobile Number", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                //    return false;
                //}
                //if (txtAdminMobileNo.Text.Length >= 7 && txtAdminMobileNo.Text.Length <= 15)
                //{
                //    MessageBox.Show(@"Invalid Administrator's Mobile Number", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                //    return false;
                //}
                if (txtEmail.Text == "")
                {
                    MessageBox.Show(@"Administrator's Email is required", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return(false);
                }

                if (RegExValidation.IsEmailValid(txtEmail.Text.Trim()))
                {
                    return(true);
                }
                MessageBox.Show(@"Invalid Administrator's Email", @"Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return(false);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                MessageBox.Show(@"Unable to validate your inputs. Please check all inputs and try again later", @"Process Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return(false);
            }
        }