Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 验证JS中的BIN编号_Javascript_Angularjs - Fatal编程技术网

Javascript 验证JS中的BIN编号

Javascript 验证JS中的BIN编号,javascript,angularjs,Javascript,Angularjs,一旦用户向我提供了他们的信用卡类型和信用卡号码,如果号码和信用卡类型不匹配,我希望根据他们的BIN显示一条错误消息: 当选择“美国运通”并输入一个数字时,无论该数字是以34或37开头,还是以任何其他数字开头,下面的代码都会生成toast消息 开关($scope.newPayment.card\u type){ 案例“美国运通”: $scope.digits=$scope.newPayment.card_number.toString().substr(0,2).valueOf(); 如果($sc

一旦用户向我提供了他们的信用卡类型和信用卡号码,如果号码和信用卡类型不匹配,我希望根据他们的BIN显示一条错误消息:

当选择“美国运通”并输入一个数字时,无论该数字是以34或37开头,还是以任何其他数字开头,下面的代码都会生成toast消息

开关($scope.newPayment.card\u type){
案例“美国运通”:
$scope.digits=$scope.newPayment.card_number.toString().substr(0,2).valueOf();
如果($scope.digits!=34 | |$scope.digits!=37){
toastr.error('卡号与卡类型不匹配');
返回;
}
打破
案例“Visa”:
$scope.digits=$scope.newPayment.card_number.toString().substr(0,1).valueOf();
如果($scope.digits!=4){
toastr.error('卡号与卡类型不匹配');
返回;
}
打破
案例“万事达卡”:
$scope.digits=$scope.newPayment.card_number.toString().substr(0,2).valueOf();
如果(51>$scope.digits>55){
$scope.digits=$scope.newPayment.card_number.toString().substr(0,4).valueOf();
如果(2221>$scope.digits>2720){
toastr.error('卡号与卡类型不匹配');
返回;
}
}
打破
案例“发现”:
$scope.digits=$scope.newPayment.card_number.toString().substr(0,4).valueOf();
如果($scope.digits!=6011){
$scope.digits=$scope.newPayment.card_number.toString().substr(0,2).valueOf();
如果($scope.digits!=65){
$scope.digits=$scope.newPayment.card_number.toString().substr(0,3).valueOf();
如果(644>$scope.digits>649){
$scope.digits=$scope.newPayment.card_number.toString().substr(0,6).valueOf();
如果(622126>$scope.digits>622925){
toastr.error('卡号与卡类型不匹配');
返回;
}
}
}
}
打破
违约:
}

我的测试用例位于代码的一条虚线上

if ($scope.digits != 34  || $scope.digits != 37 ){
将始终为真,因为数字不能同时为34和37


我更新了这篇文章,现在就可以开始了。

更详细地描述“不起作用”的含义。你有错误吗?它到底在做什么?你在调试器中跟踪代码了吗?@Amy我在调试器中没有跟踪代码-这是我第一次使用Javascript。我重新构造了代码以测试case语句、toast消息和$scope.digits值。当选择其中一种卡类型时,将显示一条toast消息,其中包含clipped$scope.digits值。我的假设是“$scope.digits!=34”计算有问题。使用调试器是一项基本的编程技能。我强烈建议您自己在调试器中戳一戳。与其他浏览器相比,我更喜欢Chrome调试工具,但YMMV除外。点击F12启动您的开发工具,转到Source选项卡,找到您的JavaScript文件。设置断点,触发代码,并逐行跟踪。