i need to check if a textarea contains some special characters, so i need to count them 2 (SMS lenght).
I wrote this piece of code but seems that it doesn't find no special chars, also if write only "€€€"
Could you please help me? Also if you would to rewrite directly function, without problem. Thank tou!
var SPECIAL_CHARS = Array('€', '%'); function charUsed() { var count = $('#text').val().length; var chars = $('#text').val().split(""); var numberOfSpecialChars = 0; if ($.inArray(chars, SPECIAL_CHARS) > -1) { numberOfSpecialChars++; } return count + numberOfSpecialChars; } // function
$.inArraytakesvalue,array, not two arrays.