Last Updated: February 25, 2016
·
2.109K
· jasonseney

Add Javascript String.trim() Support for Older Browsers

String.prototype.trim = typeof (String.prototype.trim) != "undefined" ?
    String.prototype.trim :
    function() { return this.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); };

Most newer browsers support " foobar ".trim() --> "foobar", however older browsers (IE 7 etc) need a little help. :)