private void Validate_Click(object sender, EventArgs e) { string cardNum = textBox1.Text; if (CreditCardUtility.IsValidNumber(cardNum)) { CreditCardTypeType?cardType = CreditCardUtility.GetCardTypeFromNumber(cardNum); string strCardType = (cardType == null) ? "Unknown" : cardType.ToString(); MessageBox.Show("You have entered a valid card number. The card type is {0}." + strCardType); } else { MessageBox.Show("Card failed Luhn test. Please enter a valid card number."); } }
protected void btnValidate_Click(object sender, EventArgs e) { if (txtCard.Text.Length > 0) { string cardNum = txtCard.Text.Trim(); if (CreditCardUtility.IsValidNumber(cardNum)) { CreditCardTypeType?cardType = CreditCardUtility.GetCardTypeFromNumber(cardNum); string strCardType = (cardType == null) ? "Unknown" : cardType.ToString(); showMessage(String.Format("You have entered a valid card number. The card type is {0}.", strCardType), true); } else { showMessage("Card failed Luhn test. Please enter a valid card number.", false); } } else { showMessage("Please enter a card number first.", false); } }
public ActionResult Checkoutconfirm(Models.Checkout checkout) { if (!Request.IsAuthenticated) //For login user password is not required { if (string.IsNullOrEmpty(checkout.ChoosePassword)) { ModelState.AddModelError("ChoosePassword", "The password field is required"); ModelState.AddModelError("ConfirmPassword", "The password field is required"); } else if (checkout.ChoosePassword.Length > 20 || checkout.ChoosePassword.Length < 6) { ModelState.AddModelError("ConfirmPassword", "The field New Password must be a string with a minimum length of 6 and a maximum length of 20"); } } BGBC.Core.ModelDataValidation.Instance.AlphaNumeric(ModelState, checkout.BillingAddress, true, "Billing Address", "BillingAddress"); BGBC.Core.ModelDataValidation.Instance.AlphaNumeric(ModelState, checkout.BillingAddress_2, false, "Billing Address 2", "BillingAddress_2"); BGBC.Core.ModelDataValidation.Instance.Alpha(ModelState, checkout.BillingCty, true, "Billing City", "BillingCty"); BGBC.Core.ModelDataValidation.Instance.Alpha(ModelState, checkout.BillingState, true, "Billing State", "BillingState"); BGBC.Core.ModelDataValidation.Instance.Zip(ModelState, checkout.BillingZip, true, "Billing Zip", "BillingZip"); if (!checkout.ServiceBillingAddressSame) { BGBC.Core.ModelDataValidation.Instance.AlphaNumeric(ModelState, checkout.ServiceAddress, true, "Service Address", "ServiceAddress"); BGBC.Core.ModelDataValidation.Instance.AlphaNumeric(ModelState, checkout.ServiceAddress_2, false, "Service Address 2", "ServiceAddress_2"); BGBC.Core.ModelDataValidation.Instance.Alpha(ModelState, checkout.ServiceCty, true, "Service City", "ServiceCty"); BGBC.Core.ModelDataValidation.Instance.Alpha(ModelState, checkout.ServiceState, true, "Service State", "ServiceState"); BGBC.Core.ModelDataValidation.Instance.Zip(ModelState, checkout.ServiceZip, true, "Service Zip", "ServiceZip"); } if (checkout.PaymentMethod == "eCheck") { if (string.IsNullOrEmpty(checkout.BankAccountType)) { ModelState.AddModelError("BankAccountType", "The Bank Account Type field is required."); } if (!string.IsNullOrEmpty(checkout.BankRoutingNumber)) { if (checkout.BankRoutingNumber.Trim().Length != 9) { ModelState.AddModelError("BankRoutingNumber", "Please enter a valid routing number"); } } else { ModelState.AddModelError("BankRoutingNumber", "Please enter a valid routing number"); } if (!string.IsNullOrEmpty(checkout.BankAccountNumber)) { if (checkout.BankAccountNumber.Trim().Length != 7) { ModelState.AddModelError("BankAccountNumber", "Please enter a valid account number"); } } else { ModelState.AddModelError("BankAccountNumber", "Please enter a valid account number"); } } else { if (string.IsNullOrEmpty(checkout.CardNo)) { ModelState.AddModelError("CardNo", "The Card No field is required."); } if (string.IsNullOrEmpty(checkout.CVV)) { ModelState.AddModelError("CVV", "The Card CVV field is required."); } if (!string.IsNullOrEmpty(checkout.CardNo)) { if (checkout.CardNo.Trim().Length > 0) { if (CreditCardUtility.IsValidNumber(checkout.CardNo)) { if (!string.IsNullOrEmpty(checkout.CVV)) { CreditCardTypeType?cardType = CreditCardUtility.GetCardTypeFromNumber(checkout.CardNo); if (cardType == null) { ModelState.AddModelError("CardNo", "Please enter a valid card number"); } else { checkout.CardType = (CreditCardTypeType)cardType; if (cardType == CreditCardTypeType.Amex && checkout.CVV.Trim().Length != 4) { ModelState.AddModelError("CVV", "Please enter a valid CVV number"); } else if (cardType != CreditCardTypeType.Amex && checkout.CVV.Trim().Length != 3) { ModelState.AddModelError("CVV", "Please enter a valid CVV number"); } } } } else { ModelState.AddModelError("CardNo", "Please enter a valid card number"); } } } } var query = from state in ModelState.Values from error in state.Errors select error.ErrorMessage; var errorList = query.ToList(); var allErrors = ModelState.Values.SelectMany(v => v.Errors); checkout.OrderTotal = TotalAmountToPay(checkout.CardType, checkout.PaymentMethod); if (ModelState.IsValid) { if (!Request.IsAuthenticated) { User user = _userRepository.Find(checkout.Email); if (user != null) { ModelState.AddModelError("Email", "Email is already exists"); } else { TempData["cartdata"] = checkout; return(View(checkout)); } } else { TempData["cartdata"] = checkout; return(View(checkout)); } } checkoutDropDown(); return(View("Checkout", checkout)); }