English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

if (state.match(/^california$/i)


regardless of case! it's the 'i' that ignores case!

2007-03-13 13:54:21 · answer #1 · answered by jake cigar™ is retired 7 · 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.

Hope this helps!






"alert(testIt('cAliFornIA'));" />

2007-03-13 20:58:38 · answer #2 · answered by elness 2 · 0 0

Just use if ( var == "California" )

2007-03-13 20:53:21 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers