javascript: test()

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
This entry was posted in javascript and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>