I am curious about the use of the function named test (line 3) below:
var pattern = /[1-9][1-9]{5}/;
var str = 'this is 248760!';
alert(pattern.test(str));
I saw this script in a book and there is no definition of the test(str) function.
Why does it alert true instead of giving an error?
patternis a regular expression objectA regular expression object provides many member functions such as
test(...)andtoString()to name a few…The
/‘s at the beginning and end are kind of a short hand for the following: