I have a textField and I am trying to validate it for hex values. I got a pretty good validator here. When the user presses ctr-a, it's supposed to exit the keyup event function. I used return.
The problem is, it doesn't. When you press ctr-a, the if-statement of if ctr-a
is true, but it doesn't return, it doesn't exit the function. It goes straight to the next part.
How can I exit the function when the user presses ctr-a?
document.getElementById('textField').addEventListener('keyup', function(e) {
  var keycode = e.keyCode || e.which
    // Allow: tab, home, end, left, up, right, down
  if ([9, 36, 35, 37, 38, 39, 40].indexOf(keycode) !== -1 ||
    // Allow: Ctrl || Command && a, c, x and v
    (!0 === e.ctrlKey || !0 === e.metaKey) && /65|67|88|86/.test(keycode)) {
    if (keycode === 86 && /(^[0-9A-F]{6}$)|(^[0-9A-F]{3}$)/i.test(e.target.value)) {
      console.log('Do Something with valid PASTED Hex Color');
    }
    console.log('Should return after this');
    return;
  }
  if (/^[0-9A-F]{6}$/i.test(e.target.value)) {
    console.log('Do Something with valid Hex Color');
  }
});<input type="text" id="textField" spellcheck="false" maxlength="6" />Please no JQuery answers.
 
    