Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question