0
I’m doing a simple test with Regexp on Jsfiddle and I don’t understand why
Uncaught Syntaxerror: Unexpected token var
Look at: http://jsfiddle.net/cbLs8/
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 @Sergio’s suggestion I’m having another mistake:
Uncaught Typeerror: number is not a Function
On that line here: for (i = 0; i < m.length(); i++) {
Jsfiddle updated: http://jsfiddle.net/cbLs8/1/
Regarding this is now working, but now I have another error. I edited my question.
– user7261
I just put a line before, like in the
if
. If I leave the way I was before it’s the same mistake.– user7261
@Andrey, THE
.match
gives you an array but only with one element. What exactly do you want to do? Want to make Alert of all intermediate numbers? can explain better?– Sergio
Exactly. I wanted to identify all the occurrences of
número-número
. Thematch
don’t call me back at all all the occurrences?– user7261
@Andrey your problem is that length is a property, not a function. You should use
.length
only.– Sergio
Solved now! Thank you Sergio.
– user7261
@Andrey, by the way: http://jsfiddle.net/LvuEs/
– Sergio
My doubt was the same mistakes. The regular expression I intend to change, I’m doing tests.
– user7261