The test method is a text search string matched by a regular expression. Returns true if a match is found; false otherwise.
Grammar
RegExpObject.test( string );
Here are the details of the parameters:
Return value:
Example:
<html> <head> <title>JavaScript RegExp test Method</title> </head> <body> <script type="text/javascript"> var str = "Javascript is an interesting scripting language"; var re = new RegExp( "script", "g" ); var result = re.test(str); document.write("Test 1 - returned value : " + result); re = new RegExp( "pushing", "g" ); var result = re.test(str); document.write("<br />Test 2 - returned value : " + result); </script> </body> </html>
This will produce the following results:
Test 1 - returned value : true Test 2 - returned value : false