Jump to content

Search Records - Phone Number Formatting JS not working


Recommended Posts

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(0this.value.length - 1);
        return false;
        }
  
        let v_value = (this.value.replace(/[^\d]/g''));
        console.log(v_valuethis.value);
    
        if (v_value.length >= 7 && v_value.length < 10) {
            this.value = (v_value.substring(03) + "-" + v_value.substring(37) + v_value.substring(7v_value.length));
        } else if (v_value.length >= 10) {
        this.value = ("(" + v_value.substring(03) + ") " + v_value.substring(36) + "-" + v_value.substring(610) +v_value.substring(10v_value.length));
        }
    });
});
Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...