-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbirthdate.js
More file actions
29 lines (24 loc) · 739 Bytes
/
birthdate.js
File metadata and controls
29 lines (24 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const isBirthDateValid = (birthDate) => {
if (!birthDate) return;
const day = birthDate.split('/')[0];
const month = birthDate.split('/')[1];
const year = birthDate.split('/')[2];
const adultYear = moment().subtract(18, 'years').format('YYYY');
if (day && month && year) {
if (parseInt(day) < 1 || parseInt(day) > 31) {
return false;
}
if (parseInt(month) < 1 || parseInt(month) > 12) {
return false;
}
if (parseInt(year) < 1900 || parseInt(year) > adultYear) {
return false;
}
return true;
}
};
const formatBirthdate = (date) => {
const [day, month, year] = date?.split('/');
return `${year}-${month}-${day}`;
};
module.exports = { formatBirthdate, isBirthDateValid };