-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
26 lines (23 loc) · 762 Bytes
/
Copy pathmain.js
File metadata and controls
26 lines (23 loc) · 762 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
const button = document.querySelector('#button')
const input = document.querySelector('input')
const maskOptions = {
mask: '(00) 00000-0000'
}
button.addEventListener('click', function (e) {
e.preventDefault();
let errorText = document.querySelector('#error');
if(input.value == '') {
errorText.innerHTML = 'Digite um número!';
return
}else {
errorText.innerHTML = '';
}
const cellphoneNumber = input.value
const formattedCellphoneNumber = cellphoneNumber.replace('(', '').replace(')', '').replace(' ', '').replace('-', '')
const url = `https://api.whatsapp.com/send?phone=55${formattedCellphoneNumber}`
window.open(url, '_blank').focus()
})
function configureMaskInput() {
IMask(input, maskOptions)
}
configureMaskInput()