From 66aefe3d2d585223d7af0cdb9ee8d934f78e5100 Mon Sep 17 00:00:00 2001 From: Kacper Maj <60718448+kapisolec@users.noreply.github.com> Date: Sat, 30 Jan 2021 20:44:34 +0100 Subject: [PATCH] Additional whitespace validation --- public/js/chat.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/public/js/chat.js b/public/js/chat.js index a0de579..882df65 100644 --- a/public/js/chat.js +++ b/public/js/chat.js @@ -193,10 +193,19 @@ form.addEventListener('submit', (e) => { input.focus(); // Disable form - if (input.value === '' || input.value === ' ') - return alert('Your message is blank'); - else if (input.value[0] === ' ') - return alert('Delete the space at the beggining'); + for (let index = 0; index < input.value.length; index++) { + if (input.value[index] == ' ') { + console.log('true'); + + input.value = input.value.slice(index + 1); + if (!input.value.slice(index + 1)) return; + } else { + break; + } + } + console.log('input value: ' + input.value); + if (input.value === '') return console.log('input pusty'); + button.setAttribute('disabled', 'disabled'); socket.emit('message', input.value, (error) => {