mirror of
https://github.com/cheveguerra/whatsapp-api-tutorial.git
synced 2026-04-17 19:36:59 +00:00
Add validation, formatter & some configs
This commit is contained in:
20
helpers/formatter.js
Normal file
20
helpers/formatter.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user