如何通过提供信用卡号码获取信用卡类型 [英] How Do I Get Credit Card Type By Giving The Credit Card Number
问题描述
当我们提供信用卡号时,我试图获取信用卡类型,即当用户在文本框中提供信用卡号时,必须使用luhn检查验证输入并获得卡的类型为AMEX, VISA等
我在codeproject中经历了一些例子并尝试实现但我无法将输入转换为为不同卡类型创建的类,我使用正则表达式并且c#中的代码如下所示:
C#
protected void TextBox1_TextChanged( object sender,EventArgs e)
{
int luhnCheckdigit = 0 ;
string cardNumber = TextBox1.Text.ToString();
luhnCheckdigit = checkSum(TextBox1.Text.ToString());
string TYPE = cardType(TextBox1.Text.ToString());
}
public enum cardType
{
unknown = 0 ,
MasterCard = 1 ,
VISA = 2 ,
AMEX = 3
}
public class CardtypeInfo
{
public CardtypeInfo( string regEx, int length,cardType type)
{
RegEx =正则表达式;
长度=长度;
TYpe = type;
}
public string RegEx {获得跨度>; set ; }
public int 长度{ get 跨度>; set ; }
public cardType TYpe { get ; set ; }
}
私有 静态 CardtypeInfo [] _CardTypeInfo =
{
new CardtypeInfo( ^(51 | 52 | 53 | 54 | 55), 16 ,cardType.MasterCard),
new CardtypeInfo( ^(4), 16 ,cardType.VISA),
new CardtypeInfo( ^(4), 13 ,cardType.VISA),
new CardtypeInfo( ^(34 | 37), 15 ,cardType.AMEX),
};
public cardType GetcardType( string cardNumber)
{
foreach (CardtypeInfo info in _CardTypeInfo)
{
if (cardNumber.Length == info.Length&& Regex.IsMatch(cardNumber,info.RegEx))
返回 info.TYpe;
}
return cardType.unknown;
}
请帮助我获取类卡类型的输入并在文本更改事件时显示卡的类型发生。
参考
get-the-credit-card-type-based-on-number [ ^ ]
< blockquote>参考
ASP.NET的信用卡验证器控件 [ ^ ]
获得最信用卡型为主-O n号 [ ^ ]
正则表达式-creditcard.html [ ^ ]
I am trying to get the credit card type when we give a credit card number i.e. when user gives a credit card number in a text box that input has to be taken validated using luhn check and get the type of card as AMEX, VISA etc.
I have gone through some examples in codeproject and tried to implement but i am unable to take the input into class created for different card types, i used regex and the code in c# is as below:
C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
int luhnCheckdigit = 0;
string cardNumber = TextBox1.Text.ToString();
luhnCheckdigit = checkSum(TextBox1.Text.ToString());
string TYPE = cardType(TextBox1.Text.ToString());
}
public enum cardType
{
unknown = 0,
MasterCard = 1,
VISA = 2,
AMEX = 3
}
public class CardtypeInfo
{
public CardtypeInfo(string regEx, int length, cardType type)
{
RegEx = regEx;
Length = length;
TYpe = type;
}
public string RegEx { get; set; }
public int Length { get; set; }
public cardType TYpe { get; set; }
}
private static CardtypeInfo[] _CardTypeInfo =
{
new CardtypeInfo("^(51|52|53|54|55)", 16, cardType.MasterCard),
new CardtypeInfo("^(4)", 16,cardType.VISA),
new CardtypeInfo("^(4)",13, cardType.VISA),
new CardtypeInfo("^(34|37)",15,cardType.AMEX),
};
public cardType GetcardType(string cardNumber)
{
foreach (CardtypeInfo info in _CardTypeInfo)
{
if (cardNumber.Length == info.Length && Regex.IsMatch(cardNumber, info.RegEx))
return info.TYpe;
}
return cardType.unknown;
}
please help me to get the input into the class cardtype and display the type of card when the text change event occured.
Refer
get-the-credit-card-type-based-on-number[^]
Refer
Credit Card Validator control for ASP.NET[^]
get-the-credit-card-type-based-on-number[^]
regular-expressions-creditcard.html[^]
这篇关于如何通过提供信用卡号码获取信用卡类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!