regardless of case! it's the 'i' that ignores case!
2007-03-13 13:54:21
·
answer #1
·
answered by jake cigar™ is retired7
·
0⤊0⤋
Here's an example of a JavaScript function which uses a regular expression (or regex) match. Regex patterns can be very complicated, but this is all you asked for, so I'm limiting my solution to the problem at hand.
The regex pattern itself is between the slash delimiters. The "^" and "$" are beginning- and end-of-string indicators (without them, extra characters could be inserted at the beginning or end of the user-supplied string and the match would errantly return true). And the "i" modifier indicates that the comparison should be case-insensitive.
Clicking the button passes a hard-coded string (in the onclick handler of the button) to the testIt() function, which then returns true if the hard-coded string matches "california" case-insensitively, or false if not.