信用卡/借记卡号是数字还是整数?
由于数字也可以是小数,这让我认为 CC 数字应该是整数。这是有道理的,因为我认为没有任何信用卡以 0 开头,而且它们都遵循相同的模式:
4444333322221111
所以我猜它们是一个整数,但我不太确定国际卡是什么样的?有没有0开头的?
更新
感谢您的所有回复。存储它们的次数较少(实际上我只存储最后 4 个数字),而更多的是进行快速验证检查。无论如何,我只是将其视为整数进行验证,即确保其长度在 13-16 位数字之间,并且始终不为小数。
Since a number can also be a decimal this makes me think that a CC number should be an integer. This would make sense as I don't think any credit cards start with 0 and since they all follow the same sort of pattern:
4444333322221111
So I guess they're an integer but I'm not too sure what international cards are like? Do any start with 0?
Update
Thanks for all your responses. It's less to store them (in fact I'd only store the last 4 numbers) and more to do a quick validation check. Regardless, I'd just treat it as an integer for validation, i.e. making sure that it's between 13-16 digits in length and always never a decimal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
信用卡号严格来说并不是数字。它们是字符串,但是组成长 16 位数字的数字可以分解,以便使用数字的校验和来验证该数字。
您不会对 CC 编号进行任何乘法或除法,因此我认为它应该是一个字符串。
快速前缀、长度和校验位标准
Credit card numbers are not strictly numbers. They are strings, but the numbers which make up the long 16 digit number can be exploded in order to validate the number by using the checksum of the number.
You aren't going to be doing any multiplication or division on the CC number, so it should be a string in my opinion.
Quick Prefix, Length, and Check Digit Criteria
不要为此使用整数。
根据整数的大小(取决于语言/机器),它们可能太大而无法存储为整数。
信用卡号的使用也不是整数,因为没有理由对它们进行算术运算。
您通常应该将它们视为十进制数字数组,这可能最容易存储为字符串,但可能值得一个实际的数组,这又取决于您的编程语言。
它们还包含编码的银行授权信息,如有关银行卡号的维基百科文章中所述,并且是ISO/IEC 7812 数字的特殊情况,实际上可以从零开始(尽管我认为任何信用卡都不会这样做)。如果您需要此信息,CC 号实际上可能有其自己的数据类型,并且可能某些银行实施了一种数据类型。
Don't use an integer for this.
Depending on the size of your integers (language/machine dependent), they may be too large to store as integers.
The use of credit card numbers is also not as integers, as there's no reason for doing arithmetic with them.
You should generally regard them as arrays of decimal digits, which might most easily be stored as strings, but might merit an actual array, again depending on your programming language.
They also contain encoded banking authority information as described in the wikipedia article on Bank Card Numbers, and are a special case of ISO/IEC 7812 numbers, which in fact can start with zero (though I don't think any credit cards do). If you need this information, a CC number might actually merit it's own data type, and likely some banks implement one.
就我个人而言,我总是将它们存储为字符串......它是一系列整数,很像电话号码,而不是一个大整数本身。
Personally, I always store them as a string... it is a series of integers, much like a telephone number, not one big integer itself.
最好使用单位数
int
数组。通常,各个数字用于某种类型的校验和中以验证信用卡号。它还会处理 CC# 实际上以 0 开头的情况。例如,
类似的东西,尽管它们使用的方程更复杂。 这会困难得多(即需要除法和截断)
只需
编辑:
另请记住,信用卡号中的每个数字都有其含义。例如,第三和第四位数字可能代表卡的制作状态,而第五位数字可能是发行该卡的特定银行的索引。
Better to use an array of single-digit
ints
. Often the individual digits are used in some type of checksum to validate the credit card number. It would also take care of the case that a CC# actually starts with 0.For example,
Something like that, although the equations they use are more complex. This would be a lot harder (i.e. would require division and truncation) with just
Edit:
Keep in mind also, that each digit in a credit card number means something. For example, the 3rd and 4th digits might represent the state in which the card was made, and the 5th digit might be an index to the particular bank that issued the card, for example.
我想它们是整数,因为它们(几乎可以肯定)不包含任何字母字符,也没有任何小数位。
I would imagine that they are integers as they (almost certainly) do not contain any alphabetic characters and never have any decimal places.
信用卡/借记卡号码没有以零开头(可能是由于这样的讨论)。
所有信用卡/借记卡号都有一个校验位,该
校验位 是使用 Luhn 算法计算得出的
4444333322221111
通过 Luhn 校验位测试。No credit/debit card numbers start with a zero (probably due to discussions like this).
All credit/debit card numbers have a check digit that is calculated using the Luhn algorithm
As it happens,
4444333322221111
passes the Luhn check digit test.