Assuming you only need alpha characters, get rid of other characters first using replace() :
var str='I am a student in XXX university, I am interested...'; alert(str.replace(/[^AZ]/gi, "").length);
You can add 0-9 to the character class [^AZ] if you want to count numbers as letters. If you want to remove only empty space, change the regex to /\s/g
source share