Jump to content

Vvillie

Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by Vvillie

  1. Hi! I have been using this JS Phone Number Formatting script to assist with inserting and formatting phone numbers. Now I am building a Reports Datapage and want to use the same script to assist with searching for phone numbers so you don't have to put the brackets and so on to search for a record. But for some reason it is not working and I don't know why. The Search Input ID is Value1_1 which I have inserted but when I start typing nothing happens. If someone can please help, I am still learning JS. I do apologize if this question has already been asked, I wasn't able to find anyone that has the same problem as me. Thank you for the help. My Code: var arrEl = Array.from(document.querySelector('#Value1_1')); let regExp = /^[0-9]+$/; arrEl.forEach(function(el) { el.maxLength = 14; el.addEventListener('input', function(v_e) { if (regExp.test(v_e.key)) { this.value = this.value.substr(0, this.value.length - 1); return false; } let v_value = (this.value.replace(/[^\d]/g, '')); console.log(v_value, this.value); if (v_value.length >= 7 && v_value.length < 10) { this.value = (v_value.substring(0, 3) + "-" + v_value.substring(3, 7) + v_value.substring(7, v_value.length)); } else if (v_value.length >= 10) { this.value = ("(" + v_value.substring(0, 3) + ") " + v_value.substring(3, 6) + "-" + v_value.substring(6, 10) +v_value.substring(10, v_value.length)); } }); });
×
×
  • Create New...