0

What I need to do is customer validator. The code that I have in the code behind needs to look at both the credit card type as well as the credit card number. I am not sure how to do this.

    <asp:DropDownList ID="ddlCCType" runat="server">
       <asp:ListItem Value="None">Select Card Type</asp:ListItem>
       <asp:ListItem Value="Visa">Visa</asp:ListItem>
       <asp:ListItem Value="Amex">Amex</asp:ListItem>
       <asp:ListItem Value="Mastercard">Mastercard</asp:ListItem>
    </asp:DropDownList>

    <asp:TextBox ID="txtCardNum" runat="server" Width="200px"></asp:TextBox>


    <asp:CustomValidator runat="server" id="cusCustom" controltovalidate="txtCardNum" onservervalidate="txtCard_ServerValidate" errormessage="The credit card is incorrect." />

I have the code below but not sure how to retrieve the value of the credit card type. e.Value will only return the value of the credit card number.

    protected void txtCard_ServerValidate(object sender, ServerValidateEventArgs e)
    {
      if(e.Value.Length == 8)
       ......
       e.IsValid = true;
      else
       e.IsValid = false;
    }
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Nate Pet
  • 44,246
  • 124
  • 269
  • 414

1 Answers1

1

The idea is to verify the brand of a card number based on its range. You know that: - Visa cards start with 4 - AmEx cards start with 37 (or 34, not sure anymore) - Mastercard cards start with 5

If you change the value of your items in the list so that it reflex the card range, you can verify that the card number begins with the value of the selected item.

Serge

Serge Bollaerts
  • 324
  • 2
  • 6
  • Serge, how do I retrieve the value of the credit card and the credit card type. This is my question. Thanks – Nate Pet Mar 04 '13 at 16:17