I'm doing a simple test with RegExp in JSFiddle and I do not understand why
Uncaught SyntaxError: Unexpected token var
See: link
Code:
<input type="text" id="entrada"></input>
<button id="botao">Testar</button>
$("#botao").click(function () {
if (var m = $("#entrada").val().match(/\d-\d/g)) {
for (var i = 0; i < m.length(); i++) {
alert(m[i]);
}
} else {
alert("no match");
}
});
Update
After the suggestion of @Sergio I'm having another error:
Uncaught TypeError: number is not a function
In this line here: for (i = 0; i < m.length(); i++) {
Updated JSFiddle: link