Cheat Codes - Loans - Loans - Cheat Codes - Debt Consolidation

PDA

View Full Version : Count the number of occurrences in a string


dargre
Mar 25th 2008, 4:37 am
I'm trying to limit emoticons posted for comment message.
It's easy for me to do that in PHP.
But still can't find bugless function in javascript.

Let's say I have an array of some emoticons codes, like ":sad:", etc.
So everytime someone clicks over emot icon I wish to call javascript function to check if total number of emots code exceeded my limit.
Then instead of putting code into textarea (have another good function for that) - display alert box if number exceeded limit.

Sample how function should start...


function check(object) {
var limit=5;
var content=document.getElementById(object).value;
var smileys = new Array(':)',':)',':sad:',':mad:');

....... how to retrieve number of smileys codes within content?
}

dargre
Mar 25th 2008, 5:22 am
Never mind.
Just wrote function and tested it :). It's working.
I used split method on textarea value.