Javascript .match plus jQuery keyup(), double match and strange behaviour
- by Gremo
Not really good in regular expression, but why when a match is found console.log fires two times?
$('#name').keyup(function() {
var regex = /[\€]/g;
var count = (m = $(this).val().match(regex)) ? m.length : 0; // Num matches
console.log(count);
});
Output with 'hello':
0
0
0
0
0
After adding '€' symbol to 'hello' we have:
0
0
0
0
0
1
1
After adding 'h' symbol to 'hello€' we have:
0
0
0
0
0
1
1
1
Shouldn't be just one 1 after adding '€' to 'hello'?