RegExp test() Method - Javascript RegExp

Javascript examples for RegExp:Method

Description

The test() method tests for a match in a string.

Parameter Values

Parameter Description
stringRequired. The string to be searched

Return Value

TypeDescription
Boolean Returns true if it finds a match, otherwise it returns false

The following code shows how to Search a string for the character "e":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//w  w w . java2  s. c o  m
    var str = "The following code shows how to test";
    var patt = new RegExp("e");
    var res = patt.test(str);
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

Related Tutorials