Im using thess functions to limit titles to 3 words:
function trim_words(text, limit){
var words = text.split(/\b[\s,\.-:;]*/,limit);
theNewString=words.join(" ");
return theNewString;
}
jQuery('#title').keyup(function(){
jQuery(this).val(trim_words(jQuery(this).val(),3));
});
My problem is that i cant use number as separate words.
For example
“Hello my2 test”
its ok
But if i try
“Hello 2 test”
number 2 gets deleted.
I know the problem must be in the regex but i know nothing about it. I tried
text.split(/\b[\s,\.-:;\d]*/,limit);
but no luck at all.
Thanks for your help guys!
Escape the
-character.[\.-:]means “everything between.and:“. which includes digits.