Skip to content

Commit

Permalink
WIP: dnicWithDateValidation
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavochavarria committed Sep 26, 2019
1 parent 34d5d68 commit d6c1ac1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
export const dnic = dni => {
// ([0-6][0-9]{2})-([0-2][0-9]|3[0-1])(0[1-9]|1[0-2])([0-9]{2})-([0-9]{4}[A-X])
const regex = /([0-6][d]{2})-([0-2][d]|3[0-1])(0[1-9]|1[0-2])([d]{2})-([d]{4}[A-X])/;

return regex.test(dni);
};

export const dnicWithDateValidation = dni => {
if (!dni) {
return null;
if (!dni || !dnic(dni)) {
return false;
}

const date = dni.split('-')[1];

const day = date.slice(0,2);
const month = date.slice(2, 4);
const year = date.slice(4,6);

const newDate = new Date(year, (month -1), day);

return !!newDate;
};

0 comments on commit d6c1ac1

Please sign in to comment.