Estou fazendo um teste simples com RegExp no JSFiddle e não entendo o porque do
Uncaught SyntaxError: Unexpected token var
Vejam: http://jsfiddle.net/cbLs8/
Código:
<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
Depois da sugestão do @Sergio estou tendo mais um outro erro:
Uncaught TypeError: number is not a function
Nessa linha aqui: for (i = 0; i < m.length(); i++) {
JSFiddle atualizado: http://jsfiddle.net/cbLs8/1/