The test function method in JavaScript is to return a Boolean value that indicates whether there is a pattern in the string being looked up. How to use:
Rgexp.test (str)
Where Rgexp is a required option. A regular expression object that contains a regular expression pattern or an available flag.
STR is a required option. The string on which to test the lookup.
The test function method in JavaScript checks if there is a pattern in the string, returns True if it exists, or returns false. The properties of the global RegExp object are not modified by the test method.
The following example illustrates the use of the test function method in javascript: www.82676666.com
function Testdemo (Re, s) {
var S1; Declares a variable.
Checks whether the string has a regular expression.
if (Re.test (s))//test is present.
S1 = "contains"; s contains the pattern.
Else
S1 = "does not contain"; s does not contain a pattern.
Return ("'" + S + "'" + S1 + "'" + Re.source + "'"); Returns a string.
}
The test function in JavaScript