Related articles

String.prototype.trim

If your visitor base uses older browsers (IE8 and lower), the String.prototype.trim() method might not be available. If that is the case, you can use this polyfill (this version I believe was written by Douglas Crockford);

if(!String.prototype.trim){

String.prototype.trim =function(){

returnthis.replace(/^\s*(\S*(?:\s+\S+)*)\s*$/,"$1");

};

}

The regular expression used to trim the string, can be written in different ways. Here is another version, that also gets the job done;