我有一个刷卡,我正在创建一个现场Kioske,需要预先填写一个信用卡表格,然后刷卡。我不知道为什么它没有识别任何卡片。下面是一个滑动的例子:
%B5500005555555559"TORRANCEJACK G P "2009206000000000000326000000有人能解释为什么它没有传递下面的regex模式exec吗?
// MasterCard starts with 51-55, and is 16 digits long.
var pattern = new RegExp("^%B(5[1-5][0-9]{14})\\^([A-Z ]+)/([A-Z ]+)\\^([0-9]{2})([0-9]{2})");
var match = pattern.exec(rawData);谢谢!
发布于 2017-10-10 09:09:05
我建议您使用以下模式:
/%B(5[1-5][0-9]{14})"([A-Z ]+?)\s+"([0-9]{2})([0-9]{2})/见regex演示。注意,您必须对最后一个([0-9]{2})([0-9]{2})组进行微调,才能将正确的数字转换为所需的组数。
JS演示:
var rx = /%B(5[1-5][0-9]{14})"([A-Z ]+?)\s+"([0-9]{2})([0-9]{2})/g;
var s = '%B5500005555555559"TORRANCEJACK G P "2009201800000000000326000000';
var matches = rx.exec(s);
if (matches) {
console.log("Number: " + matches[1]); // => number
console.log("Name: " + matches[2]); // => name
console.log("Exp. year: " + matches[3]); // => exp year
console.log("Exp. month: " + matches[4]); // => exp month
}
https://stackoverflow.com/questions/46658510
复制相似问题