Finding a few words in the line



  • How can you identify a few words to search the line? Now it's not exactly a word, but even if there's a part of it. He'll find, like, hello.

    function validateText(){
      var pattern = /hello|hi/;
        var content = $('.validateText').val().toLowerCase();
        var exists = pattern.test(content);
    

    return exists;
    }

    $("#3DSend").click(function(e){
    e.preventDefault();

    const exists = validateText();
    
    if(exists) {
    
        alert("Слово найдено");
    
    }
    

    })

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input class="validateText" value="" />
    <button id="3DSend">Проверить</button>



  • You've got regex using the wrong syntaxy!

    var pattern = /hello|hi/;
    

    If you need a separate word

    var pattern = /(hello|hi)\b/;
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2