// function left trim used by trim method to trim the left blank spaces function ltrim(st) { newString = '' for(i=0; i < st.length ; i++) { if(st.substring(i,i+1)==' ') continue; else{ newString = st.substring(i) break } } return newString; } // function right trim used by trim method to trim the right blank spaces function rtrim(st) { newString = '' for(i = st.length ; i > 0 ; i--) { if(st.substring(i-1,i)==' ') continue; else{ newString = st.substring(0,i) break } } return newString; } // funtion calls left trim and right trim to trim all blank spaces. function trim(st) { return rtrim(ltrim(st)) } String.prototype.trim = function() { return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); }