lib/generators/nifval/templates/nifval.js in nifval-0.2.0 vs lib/generators/nifval/templates/nifval.js in nifval-0.2.1

- old
+ new

@@ -1,9 +1,14 @@ function nifval(nif){ // NIF not provided if(!nif) return false; + // Add zeros to the left if applyable, and accept lowercase + if(nif.length < 9) + nif = repeat("0",9-nif.length) + nif; + nif = nif.toUpperCase(); + // Format if(!nif.match(/^[A-Z]{1}\d{7}[A-Z0-9]{1}$/) && !nif.match(/^[0-9]{8}[A-Z]{1}$/)) return false; if(nif.match(/^[0-9]{8}[A-Z]{1}$/)){ // Standard NIF @@ -33,6 +38,13 @@ return nif[8] == "TRWAGMYFPDXBNJZSQVHLCKE"[parseInt(niff.substring(0,8),10) % 23]; }else{ return false } } +} + +function repeat(s, n) { + var r=""; + for (var a=0;a<n;a++) + r+=s; + return r; }