-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,47 @@ | ||
export const dnic = dni => { | ||
if(!dni){ | ||
return false; | ||
} | ||
const dnic = dni => { | ||
if (!dni) { | ||
return false; | ||
} | ||
|
||
const regex = /([0-6][d]{2})-([0-2][d]|3[0-1])(0[1-9]|1[0-2])([d]{2})-([d]{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); | ||
return regex.test(dni); | ||
}; | ||
|
||
export default dnic; | ||
|
||
export const dnicWithDateValidation = dni => { | ||
if (!dnic(dni)) { | ||
return false; | ||
} | ||
if (!dnic(dni)) { | ||
return false; | ||
} | ||
|
||
const date = dni.split('-')[1]; | ||
const date = dni.split('-')[1]; | ||
|
||
const day = date.slice(0,2); | ||
const month = date.slice(2, 4); | ||
const year = date.slice(4,6); | ||
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; | ||
}; | ||
const newDate = new Date(year, month - 1, day); | ||
|
||
return Boolean(newDate); | ||
}; | ||
|
||
export const getRegionByDni = dni => { | ||
if (!dnic(dni)) { | ||
return false; | ||
} | ||
if (!dnic(dni)) { | ||
return false; | ||
} | ||
|
||
const region = dni.split('-')[0]; | ||
const region = dni.split('-')[0]; | ||
|
||
const mapRegions = [ | ||
{'001' : 'Managua'}, | ||
{'002' : 'San Rafael Del Sur'}, | ||
{'003' : 'Tipitapa'}, | ||
{'004' : 'Villa Carlos Fonseca'}, | ||
{'005' : 'San Francisco Libre'} | ||
]; | ||
const mapRegions = [ | ||
{'001': 'Managua'}, | ||
{'002': 'San Rafael Del Sur'}, | ||
{'003': 'Tipitapa'}, | ||
{'004': 'Villa Carlos Fonseca'}, | ||
{'005': 'San Francisco Libre'} | ||
]; | ||
|
||
const foundRegion = mapRegions.find(r => r[region]); | ||
const foundRegion = mapRegions.find(r => r[region]); | ||
|
||
return Object.values(foundRegion)[0]; | ||
} | ||
return Object.values(foundRegion)[0]; | ||
}; |