I have a small JavaScript function that I would like to implement in an Angular service or controller.
function cprCheck(frm) {
var cpr = frm.cpr.value;
if (cpr.match(/[0-9]{6}\-[0-9]{4}/)) {
cpr = cpr.replace(/\-/g, "");
var chk = 0;
for (i = 9; i > -1; i--) {
chk += (+cpr.charAt(i)) * ((i > 2) ? (10 - i) : (4 - i));
}
if (chk % 11 == 0) return true;
}
return false;
}
When using the functions value, match, and replace, why am I getting an exception?