Add validation, formatter & some configs

This commit is contained in:
Nur Muhammad
2020-10-10 12:42:55 +08:00
parent 4e11203d01
commit 4c347048a7
4 changed files with 99 additions and 3 deletions

20
helpers/formatter.js Normal file
View File

@@ -0,0 +1,20 @@
const phoneNumberFormatter = function(number) {
// 1. Menghilangkan karakter selain angka
let formatted = number.replace(/\D/g, '');
// 2. Menghilangkan angka 0 di depan (prefix)
// Kemudian diganti dengan 62
if (formatted.startsWith('0')) {
formatted = '62' + formatted.substr(1);
}
if (!formatted.endsWith('@c.us')) {
formatted += '@c.us';
}
return formatted;
}
module.exports = {
phoneNumberFormatter
}