也许我在这里被杀了,但我需要问一下,如果通过RegEx可以实现这种疯狂,请参阅我有这个Javascript / jQyery函数来验证委内瑞拉(RIF)的增值税号:
function(value) {
if (value === '') {
return true;
}
var $rif = value.val();
var $last_number = $rif.substr($rif.length - 1);
var $number = $rif.substr(0, 8);
$valid = /^([VEJPG]{1})([0-9]{9}$)/.test($rif_type + $rif);
if ($valid) {
if ($rif_type == "V") {
$sum = 1 * 4;
} else if ($rif_type == "E") {
$sum = 2 * 4;
} else if ($rif_type == "J") {
$sum = 3 * 4;
} else if ($rif_type == "P") {
$sum = 4 * 4;
} else if ($rif_type == "G") {
$sum = 5 * 4;
}
$n0 = $number.charAt(0) * 3;
$n1 = $number.charAt(1) * 2;
$n2 = $number.charAt(2) * 7;
$n3 = $number.charAt(3) * 6;
$n4 = $number.charAt(4) * 5;
$n5 = $number.charAt(5) * 4;
$n6 = $number.charAt(6) * 3;
$n7 = $number.charAt(7) * 2;
$sum += $n0 + $n1 + $n2 + $n3 + $n4 + $n5 + $n6 + $n7;
$mod = $sum % 11;
$last_val = 11 - $mod;
if ($last_val == 11 || $last_val == 10) {
$last_val = 0;
}
if ($last_number == $last_val) {
return true;
} else {
return false;
}
}
return false;
}
我问是否有可能写一个RegEx来检查相同的,如果是,怎么做?
这些是有效的增值税号:
J298081775
J295809000
J298720620