August 1999
Intermediate to advanced
1488 pages
72h 53m
English
regexp.test()
The test() method of the RegExp object is used to test for a pattern match in a string. Returns Boolean value true or false.
Listing 6.226 shows how the test() method is used.
<html> <body> <script language="JavaScript"> <!–– Hide // create a new regular expression myExp = new RegExp("hope", "g"); // define a string object str = "I hope everything is going well."; // test to see if the regular expression exists in the string if(myExp.test(str)){ document.write("The test found \"hope\" in the string: " + "<b>" + " I hope everything is going well" + "</b>"); } // End Hide ––> </script> </body> ... |
Read now
Unlock full access