Regular Expression



Write a javascript code to check whether the string contains the given pattern or not.


<html>
  <head>
    <script>

         var p = /student/i; 

         function testMatch() 
         {
            var str = document.getElementById("textfield").value;

            if (p.test(str)) 
            {
                alert("The string \"" + str + "\" contains the given pattern.");
            } 
            else
            {
                alert("The string \"" + str + "\" does not contain the given pattern.");
            } 
        }

    </script>
  </head>
<body>

        <h3> Checking the availability of a string </h3>

        Enter the String:<input type="text" id="textfield" />

        <input type="button" value="Check" onclick="testMatch();" />

  </body>
</html>

Output: