Y
Y
Yuber70 Roshe2021-08-11 16:12:21
JavaScript
Yuber70 Roshe, 2021-08-11 16:12:21

How to use data from input in regular expression?

There is a word on the page. For example "Test".
The user must enter into the input the text that is visible on the screen.
If the input is invalid, character input is prohibited.
That is, the user in this example should only be able to enter the word "Test".

let  test = document.querySelector('.test').innerHTML;

ball.forEach(function(item) {
    item.onclick= function(){
        let  input = document.querySelector('.input').value;
        input+=item.innerHTML;
        
        if (регулярное выражение -????) {
          parent.innerHTML += input;
        }
}});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Bereznikov, 2021-08-16
@gdt

Well, then your regular expression must match the word displayed on the page. In your case - "Test" (without quotes), initialize it with the value test. It will be even easier to do without expressions at all, compare strings and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question