Executes the search for a match between a regular expression and a specified string. Returns true or false.
regexp.test(str)
regexp
The name of the regular expression. It can be a variable name or a literal.
str
(Optional) The string against which to match the regular expression. If omitted, the value of RegExp.input is used.
When you want to know whether a pattern is found in a string use the test method (similar to the String.search method); for more information (but slower execution) use the exec method (similar to the String.match method).
The following example prints a message which depends on the success of the test: