Skip to content

Instantly share code, notes, and snippets.

@gutjoa
gutjoa / dni_cl_validator.js
Created February 24, 2021 00:26 — forked from matiaslopezd/dni_cl_validator.js
Chilean DNI validator and get in JSON { run: Number/String, adv: Number/String, dv: Number/String, valid: Boolean }
function DNI_CL({ run, string }){
if(run !== '' && (typeof run === "string" || typeof run === "number")){
function format(n){
if (typeof n === 'string') {
// Remove '.' if exist
n = (n.includes('.')) ? n.split('.').join('') : n;
// Remove '-' if exist
n = (n.includes('-')) ? n.split('-').join('') : n;