Example #1
0
 private bool CustomValidation()
 {
     if (trAmount.Visible)
     {
         decimal amount = AlwaysConvert.ToDecimal(Request.Form[Amount.UniqueID]);
         if (amount <= 0 || (this.MaxPaymentAmount > 0 && amount > this.MaxPaymentAmount))
         {
             CustomValidator invalidAmount = new CustomValidator();
             invalidAmount.ID = "invalidAmountValidator";
             invalidAmount.ValidationGroup = this.ValidationGroup;
             invalidAmount.Text            = "*";
             invalidAmount.ErrorMessage    = "Invalid amount.  Payment must be greater than zero and no more than " + MaxPaymentAmount.LSCurrencyFormat("lc") + ".";
             invalidAmount.IsValid         = false;
             phAmount.Controls.Add(invalidAmount);
             return(false);
         }
     }
     return(true);
 }
        private bool CustomValidation()
        {
            bool hasErrors = false;

            if (trAmount.Visible)
            {
                decimal amount    = AlwaysConvert.ToDecimal(Request.Form[Amount.UniqueID]);
                decimal maxAmount = AlwaysConvert.ToDecimal(this.MaxPaymentAmount.LSCurrencyFormat("lc"));
                if (amount <= 0 || (maxAmount > 0 && amount > maxAmount))
                {
                    CustomValidator invalidAmount = new CustomValidator();
                    invalidAmount.ValidationGroup = this.ValidationGroup;
                    invalidAmount.Text            = "*";
                    invalidAmount.ErrorMessage    = "Invalid amount.  Payment must be greater than zero and no more than " + MaxPaymentAmount.LSCurrencyFormat("lc") + ".";
                    invalidAmount.IsValid         = false;
                    phAmount.Controls.Add(invalidAmount);
                    hasErrors = true;
                }
            }

            //if intl instructions are visible, we must validate additional rules
            if (trIntlInstructions.Visible)
            {
                PaymentMethod m = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue));
                if (m != null)
                {
                    if (m.IsIntlDebitCard())
                    {
                        // INTERNATIONAL DEBIT CARD, ISSUE NUMBER OR START DATE REQUIRED
                        bool invalidIssueNumber = (!Regex.IsMatch(IssueNumber.Text, "\\d{1,2}"));
                        bool invalidStartDate   = ((StartDateMonth.SelectedIndex == 0) || (StartDateYear.SelectedIndex == 0));
                        if (invalidIssueNumber && invalidStartDate)
                        {
                            IntlDebitValidator1.IsValid = false;
                            IntlDebitValidator2.IsValid = false;
                            hasErrors = true;
                        }
                        // CHECK START DATE IS IN PAST
                        int selYear = AlwaysConvert.ToInt(StartDateYear.SelectedValue);
                        int curYear = DateTime.Now.Year;
                        if (selYear > curYear)
                        {
                            StartDateValidator1.IsValid = false;
                            hasErrors = true;
                        }
                        else if (selYear == curYear)
                        {
                            int selMonth = AlwaysConvert.ToInt(StartDateMonth.SelectedValue);
                            int curMonth = DateTime.Now.Month;
                            if (selMonth > curMonth)
                            {
                                StartDateValidator1.IsValid = false;
                                hasErrors = true;
                            }
                        }
                    }
                    else
                    {
                        // CREDIT CARD, CVV IS REQUIRED
                        if (!Regex.IsMatch(SecurityCode.Text, "\\d{3,4}"))
                        {
                            SecurityCodeValidator2.IsValid = false;
                            hasErrors = true;
                        }
                    }
                }
            }

            return(!hasErrors);
        }