Untitled
unknown
plain_text
2 years ago
712 B
7
Indexable
ValidateDigit(control: AbstractControl) {
let pattern = new RegExp(/[A-Za-z]/);
let cusip = control. value ? control.value.split(""): [];
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ*@#";
if (cusip.length > 0 && cusip.length == 9) {
let sum = 0;
for (let i = 0; i < 8; i++) {
let v = 0;
let c = cusip[i].toUpperCase();
if ((!isNaN(parseFloat(c)) && isFinite(c))) v = c;
else if (pattern.test(c)) v = alphabet.indexOf(c) + 10 // lower case letters apparently inv if ((i % 2) != 0) v = 2 // check if odd as using 0-based indexing v = (v % 10) + (v / 10);
sum += parseInt(v.toString());
白
}
if (parseInt(cusip[8]) != (10 - (sum %10)) % 10) { return { validUrl: true }
}
return null;
}
return null;Editor is loading...
Leave a Comment