Definition and Usage
The test() method is used to search for a match of a regular expression in a string.
This method returns true if a match is found, and false if not.
Syntax
RegExpObject.test(string) |
| Parameter | Description |
|---|---|
| RegExpObject | Required. The regular expression to use |
| string | Required. The string to search |
Example
In the following example we will search for “W3Schools”:
<script type="text/javascript">
var str = "Visit W3Schools";
var patt1 = new RegExp("W3Schools");
var result = patt1.test(str);
document.write("Result: " + result);
</script>
source: http://www.w3schools.com/jsref/jsref_test_regexp.asp