我目前正在开展一个项目,我正在使用线路阅读器将信用卡号输入验证器和标识符。假设我输入了10个号码,他们来自四家不同的信用卡公司。我想忽略三家公司,只显示其余公司的数字。
这家公司的规则(条件)是它必须有15位数字,并以37或34开头
4111111111111111
4111111111111
4012888888881881
378282246310005
6011111111111117
5105105105105100
5105105105105106
9111111111111111
371449635398431
378734493671000
这是我目前的临时模块:
export const isAmex = (creditCard: string): boolean =>
creditCard.length === 15 &&
(creditCard.substring(0, 2) === '37' || creditCard.substring(0, 2) === '34')
export const is2Amex = (creditCard: string): boolean =>
creditCard.length === 15 &&
(creditCard.substring(0, 2) === '37' || creditCard.substring(0, 2) === '34')
export const ifIsntAmex = (creditCard: string) => {
if (!is2Amex(creditCard)) {
return ' '
} else {
return creditCard
}
}
export const getAmexName = (creditCard: string) => {
if (!isAmex(creditCard)) {
return ' '
} else {
return 'AMEX'
}
}
以下是索引的一部分:
const outputAmex: string[] = []
lineReader.on('line', (creditCard: string) => {
outputAmex.push(
`${getAmexName(creditCard)}: ${ifIsntAmex(creditCard)}
(${cardValidator(creditCard) ? 'valid' : 'invalid'})`
)
})
lineReader.on('close', () => {
fs.writeFile('./data/Amex.txt', outputAmex.join('\n'), err => {
if (err) throw err
console.log('The file has been saved!')
})
})
它返回如下内容:
: (valid)
: (invalid)
: (valid)
AMEX: 378282246310005 (invalid)
: (valid)
: (valid)
: (invalid)
: (invalid)
AMEX: 371449635398431 (invalid)
AMEX: 378734493671000 (invalid)
我如何忽略非美国运通线?
答案 0 :(得分:0)
lineReader.on('line', (creditCard: string) => {
if (is2Amex(creditCard)) {
outputAmex.push();
}
})
类似的东西?
答案 1 :(得分:0)
{{1}}
这最终对我有用。