Example #1
0
 public static ValidationResult ValidateToPay(string ToPay)
 {
     var result = new ValidationResult
     {
         IsValid = true
     };
     decimal topay;
     var error = new StringBuilder();
     if (!Decimal.TryParse(ToPay, out topay))
     {
         result.Error += "Wrong ToPay format! Can have only numbers" + Environment.NewLine;
         result.IsValid = false;
     }
     else if (Regex.IsMatch(ToPay, @"\.\d\d\d"))
     {
         result.Error += "Cannot have more than 2 value digits after '.'" + Environment.NewLine;
         result.IsValid = false;
     }
     else if (Convert.ToDecimal(ToPay) < 0)
     {
         result.Error += "Wrong ToPay format! Can have only non-negative numbers" + Environment.NewLine;
         result.IsValid = false;
     }
     else if (Convert.ToDecimal(ToPay) == 0)
     {
         result.Error += "ToPay can't be zero" + Environment.NewLine;
         result.IsValid = false;
     }
     if (ToPay.Length > ToPayMaxLength)
     {
         result.Error += "ToPay must not be longer than "+ ToPayMaxLength + " symbols!" + Environment.NewLine;
         result.IsValid = false;
     }
     return result;
 }
Example #2
0
 private bool Validate(bool RPassportNo, bool ToPay, bool RequestId, bool APassportNo)
 {
     Validation.ValidationResult validationResult = new Validation.ValidationResult();
     if (RPassportNo)
     {
         validationResult = OperatorValidation.ValidatePassportNo(RepaymentPassportNo.Text);
     }
     if (ToPay)
     {
         validationResult = OperatorValidation.ValidateToPay(RepaymentToPay.Text);
     }
     if (RequestId)
     {
         validationResult = OperatorValidation.ValidateRequestId(RequestRequestId.Text);
     }
     if (APassportNo)
     {
         validationResult = OperatorValidation.ValidatePassportNo(AllowCreditPassportNo.Text);
     }
     if (validationResult.IsValid)
     {
         return(true);
     }
     else
     {
         MessageBox.Show(validationResult.Error);
         return(false);
     }
 }
Example #3
0
        public static ValidationResult ValidateRequestId(string RequestId)
        {
            var result = new ValidationResult
            {
                IsValid = true
            };

            var error = new StringBuilder();
            int request;

            if (!Int32.TryParse(RequestId, out request))
            {
                result.Error += "Wrong Request id format! Can have only numbers" + Environment.NewLine;
                result.IsValid = false;
            }
            else if (Convert.ToDecimal(RequestId) < 0)
            {
                result.Error += "Wrong RequestId format! Can have only non-negative numbers" + Environment.NewLine;
                result.IsValid = false;
            }
            if (RequestId.Length > RequestIdMaxLength)
            {
                result.Error += "RequestId must not be longer than "+ RequestIdMaxLength + " symbols!" + Environment.NewLine;
                result.IsValid = false;
            }
            return result;
        }
Example #4
0
        public static ValidationResult Validate(string userName, string password, string passwordRepeat)
        {
            var result = new ValidationResult
            {
                IsValid = true
            };

            if (!UserNameRegex.IsMatch(userName))
            {
                result.Error = "Username can consist only of letters, words in username can be separated by single uderscores(_), dashes(-) or dots(.)!\n"+
                    "Username must begin and end with letter!"
                    +"Example: 'I_m.newly-created_User'";
                result.IsValid = false;
            }

            if (password.Length < PasswordMinLength)
            {
                result.Error = "Password must be at least 5 symbols long!";
                result.IsValid = false;
            }

            if (password != passwordRepeat)
            {
                result.Error = "Password and re-enterd password do not match!";
                result.IsValid = false;
            }

            if (!PasswordRegex.IsMatch(password))
            {
                result.Error = "Password must contain letters!";
                result.IsValid = false;
            }

            return result;
        }
Example #5
0
        public static ValidationResult Validate(string lastName, string name, /*string patronymic,*/ DateTime birthday, string mobile, string email, string passportNo,
            DateTime passwordExpiration, string passportIdentityNo, string passportAuthority, string placeOfResidence, string registrationAddress)
        {
            var result = new ValidationResult
            {
                IsValid = true
            };

            var error = new StringBuilder();

            if (!NameRegex.IsMatch(lastName))
            {
                error.AppendLine("Wrong lastname format! Can have only words separated by single spaces or dashes. Lastname must start with capital letter");
                result.IsValid = false;
            }

            if (!NameRegex.IsMatch(name))
            {
                error.AppendLine("Wrong name format!\n Can have only words separated by single spaces or dashes. Name must start with capital letter");
                result.IsValid = false;
            }

            //if (!NameRegex.IsMatch(patronymic))
            //{
            //    error.AppendLine("Wrong patronymic format!\n Can have only words separated by single spaces or dashes. Patronymic must start with capital letter");
            //    result.IsValid = false;
            //}

            if (!MobileRegex.IsMatch(mobile))
            {
                error.AppendLine("Wrong mobile phone format!\n Enter your phone number in the following format: +1-1234567890 3754412345678 23-1234567890");
                result.IsValid = false;
            }

            if (!EmailRegex.IsMatch(email))
            {
                error.AppendLine("Wrong email!\n Enter your email address in format: [email protected]");
                result.IsValid = false;
            }

            if (!PassportNoRegex.IsMatch(passportNo))
            {
                error.AppendLine("Wrong passport number!\n Enter your passport number in format: AB1122333!");
                result.IsValid = false;
            }

            if (!PassportIdentityNoRegex.IsMatch(passportIdentityNo))
            {
                error.AppendLine("Wrong passport identity number format!\n");
                result.IsValid = false;
            }

            result.Error = error.ToString();
            return result;
        }
Example #6
0
        public static ValidationResult Validate(string Amount, string Salary)
        {
            var result = new ValidationResult
            {
                IsValid = true
            };

            var error = new StringBuilder();
            decimal amount,salary;
            if (!Decimal.TryParse(Amount, out amount))
            {
                result.Error += "Wrong Amount format! Can have only numbers" + Environment.NewLine;
                result.IsValid = false;
            }
            else if (Convert.ToDecimal(Amount) < 0)
            {
                result.Error += "Wrong Amount format! Can have only non-negative numbers" + Environment.NewLine;
                result.IsValid = false;
            }
            else if (Convert.ToDecimal(Amount) == 0)
            {
                result.Error += "Amount can't be zero" + Environment.NewLine;
                result.IsValid = false;
            }
            if (Amount.Length > AmountMaxLength)
            {
                result.Error += "Amount must not be longer than 12 symbols!" + Environment.NewLine;
                result.IsValid = false;
            }

            if (!Decimal.TryParse(Salary, out salary))
            {
                result.Error += "Wrong Salary format! Can have only numbers" + Environment.NewLine;
                result.IsValid = false;
            }
            else if (Convert.ToDecimal(Salary) < 0)
            {
                result.Error += "Wrong Salary format! Can have only non-negative numbers" + Environment.NewLine;
                result.IsValid = false;
            }
            else if (Convert.ToDecimal(Salary) == 0)
            {
                result.Error += "Salary can't be zero" + Environment.NewLine;
                result.IsValid = false;
            }
            if (Salary.Length > SalaryMaxLength)
            {
                result.Error += "Salary must not be longer than 12 symbols!" + Environment.NewLine;
                result.IsValid = false;
            }
            return result;
        }
Example #7
0
        public static ValidationResult ValidatePassportNo(string PassportNo)
        {
            var result = new ValidationResult
            {
                IsValid = true
            };

            var error = new StringBuilder();

            if (!PassportNoRegex.IsMatch(PassportNo))
            {
                result.Error += "Wrong passport number!\n Enter your passport number in format: AB1122333!" + Environment.NewLine;
                result.IsValid = false;
            }
            if (PassportNo.Length > PassportNoMaxLength)
            {
                result.Error += "PassportNo must not be longer than "+ PassportNoMaxLength + " symbols!" + Environment.NewLine;
                result.IsValid = false;
            }

            return result;
        }
Example #8
0
 private bool Validate(bool RPassportNo, bool ToPay, bool RequestId , bool APassportNo)
 {
     Validation.ValidationResult validationResult = new Validation.ValidationResult();
     if (RPassportNo)
     {
         validationResult = OperatorValidation.ValidatePassportNo(RepaymentPassportNo.Text);
     }
     if(ToPay)
     {
         validationResult = OperatorValidation.ValidateToPay(RepaymentToPay.Text);
     }
     if (RequestId)
     {
         validationResult = OperatorValidation.ValidateRequestId(RequestRequestId.Text);
     }
     if (APassportNo)
     {
         validationResult = OperatorValidation.ValidatePassportNo(AllowCreditPassportNo.Text);
     }
     if (validationResult.IsValid)
     {
         return true;
     }
     else
     {
         MessageBox.Show(validationResult.Error);
         return false;
     }
 }
Example #9
0
        public static ValidationResult Validate(
            string name,
            string intTimeMonth,
            string decPercentPerYear,
            string currency,
            string decFinePercent,
            string decMinAmount,
            string decMaxAmount)
        {
            var result = new ValidationResult() { IsValid = true };

            if (string.IsNullOrEmpty(name))
            {
                result.IsValid = false;
                result.Error = "Name must be not empty!\n";
            }
            else
            {
                if (name.Length > NameMaxLength)
                {
                    result.IsValid = false;
                    result.Error = string.Format("Name cannot be more than {0} symbols long!\n", NameMaxLength);
                }
            }

            int timeMonth;
            if (int.TryParse(intTimeMonth, out timeMonth))
            {
                if (timeMonth <= 0)
                {
                    result.IsValid = false;
                    result.Error += "Time must be positive number!\n";
                }
                if (timeMonth >= MaxTimeMonth)
                {
                    result.IsValid = false;
                    result.Error += string.Format("Time cannot be more than {0}!\n", MaxTimeMonth);
                }
            }
            else
            {
                result.Error += "Time must be valid positive integer number!\n";
            }

            decimal percentPerYear;
            if (decimal.TryParse(decPercentPerYear, out percentPerYear))
            {
                if (percentPerYear <= 0)
                {
                    result.IsValid = false;
                    result.Error += "Percent Per Year must be positive number!\n";
                }
            }
            else
            {
                result.IsValid = false;
                result.Error += "Percent Per Year must be valid positive integer number!\n";
            }

            decimal finePercentPerYear;
            if (decimal.TryParse(decFinePercent, out finePercentPerYear))
            {
                if (finePercentPerYear <= 0)
                {
                    result.IsValid = false;
                    result.Error += "Fine Percent Per Year must be positive number!\n";
                }
            }
            else
            {
                result.IsValid = false;
                result.Error += "Fine Percent Per Year must be valid positive integer number!\n";
            }

            decimal minAmount;
            if (decimal.TryParse(decMinAmount, out minAmount))
            {
                if (minAmount <= 0)
                {
                    result.IsValid = false;
                    result.Error += "Min Amount must be positive number!\n";
                }
            }
            else
            {
                result.IsValid = false;
                result.Error += "Min Amount must be valid positive integer number!\n";
            }

            decimal maxAmount;
            if (decimal.TryParse(decMaxAmount, out maxAmount))
            {
                if (maxAmount <= 0)
                {
                    result.IsValid = false;
                    result.Error += "Max Amount must be positive number!\n";
                }
                if (maxAmount < minAmount)
                {
                    result.IsValid = false;
                    result.Error += "Max Amount must be greater than Min AMount!\n";
                }
            }
            else
            {
                result.IsValid = false;
                result.Error += "Max Amount must be valid positive integer number!\n";
            }

            return result;
        }