Hi,
My requirement is to allow user to enter words till 500.
After 500 words,it shouldn’t allow the user.
For this we have written the jquery function as below
This is working fine if user is filling the text box manually.
But if user copies text from some other page and paste the text in textbox.
There problem comes in i.e
Once text is pasted,it is displaying as 509 words and
It is allowing user to enter text after 509 words.
Please share your ideas/thoughts on the same.
function stopDataEntry(mytxt, myspan) {
var cnt = 500;
var s = mytxt.value;
s = s.replace(/(^\s*)|(\s*$)/gi, "");
s = s.replace(/[ ]{2,}/gi, "");
s = s.replace(/\n /, "\n");
var wordCount = s.split(' ').length;
if (parseInt(wordCount)> cnt) {
mytxt.value = mytxt.value.substring(0, mytxt.value.length - 1);
}
if (cnt - parseInt(wordCount) >= 0) {
document.getElementById(myspan).innerHTML = "Remaining word(s):" + (mytxt.value != "" ? (cnt - parseInt(wordCount)) : cnt);
}
else {
document.getElementById(myspan).innerHTML = "Remaining word(s):0";
}
}
Regards,
Sudheer
Thanks & Regards, Sudheer