Description
The test() method tests for a match in a string and return true if it finds a match, false otherwise.
This method has the form:
RegExpObject.test(string)
Parameter | Description |
---|---|
string | (required) The string to be searched |
Examples
The following example shows the basic use of this method.
<script>
var str = "Hello JavaScript";
// look for "Java"
var pat = /Java/g;
var result = pat.test(str);
document.write("Result: " + result);
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|