여러모로 유용한 트림 함수를 자바스크립트의 String객체게 바로 붙여서 사용할 수 있도록 하는 방법입니다.
좌/우/양쪽/모든공백을 아래와 같이 사용할 수 있습니다.
String.prototype.trim=function(){return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');};
String.prototype.ltrim=function(){return this.replace(/^\s+/,'');}
String.prototype.rtrim=function(){return this.replace(/\s+$/,'');}
String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');}