如何检索信用卡类型的值

时间:2013-03-04 15:51:56

标签: c# asp.net

我需要做的是客户验证器。我在后面的代码中的代码需要查看信用卡类型以及信用卡号。 我不知道该怎么做。

    <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." />

我有以下代码,但不知道如何检索信用卡类型的值。 e.Value仅返回信用卡号的值。

    protected void txtCard_ServerValidate(object sender, ServerValidateEventArgs e)
    {
      if(e.Value.Length == 8)
       ......
       e.IsValid = true;
      else
       e.IsValid = false;
    }

1 个答案:

答案 0 :(得分:1)

这个想法是根据其范围验证卡号的品牌。你知道的: - Visa卡以4开头 - AmEx卡以37开头(或34,不再确定) - 万事达卡以5开头

如果更改列表中项目的值以使其反映卡片范围,则可以验证卡片编号是否以所选项目的值开头。

塞尔