How to monitor input in javascript

Viewed 80

I'm developing an extension for chrome that should check input fields in a form using REGEX

To do this, I need to get an input field, I do it as follows:

let input = document.getElementById("id_input");

After that, I have to add some function that whenever there is any change in the input, it applies a Regex in the value, formatting it in real time if the user enters some invalid value.

I tried to make a sketch of this code as follows:

input.addEventListener("change", function () {
    let v = document.getElementById('search').value;
    v.replace(/world/g, "universe");
});

For some reason it's not working, I don't have as much knowledge in javascript and I don't know if the code I made is wrong or if I need to add something else to it.

0 Answers
Related