The following script works fine so long as the CASE of the question and answer match.
Is there a way to set the ‘regex’ to test for a match regardless of the CASE?
The problem is demonstrated in the code when you choose ‘menu’ vs ‘MENU’ and ‘calculator’ vs ‘CALCULATOR’.
[code]
<html>
<head>
<title>RegEx Menu</title>
<script type=”text/javascript”>
QAnswer = ‘calendar|calculator|TabBox|menu’;
function Response(question) {
/* following works, but must match CASE in question/answer */
var re = new RegExp(QAnswer); // create regular expression from a variable
answer = question.match(re) ? ‘Match Found’ : ‘No MATCH available’;
return answer;
}
</script>
</head>
<body>
<select id=”SBox” onchange=”alert(Response(this.value))”>
<option value=””>Query about</option>
<option value=”calendar”>Calendar</option>
<option value=”calculator”>Calculator</option>
<option value=”CALCULATOR”>CALCULATOR</option>
<option value=”TabBox”>TabBox</option>
<option value=”menu”>Menu</option>
<option value=”MENU”>MENU</option>
<option value=””>Other</option>
</select>
</body>
</html>
I have tried the following, but each gives errors:
[COLOR=”Red”]answer = question.match(/re/i) ? ‘Match Found’ : ‘No MATCH available’;
and
[COLOR=”Red”]
var re = new RegExp(QAnswer.toUpperCase());
answer = question.toUpperCase().match(re) ? ‘Match Found’ : ‘No MATCH available’;
A blank question (”) works fine as well. Any ideas on what else to change for the .match() function using a regular expression.