Posted By


anagai on 04/30/11

Tagged


Statistics


Viewed 305 times
Favorited by 0 user(s)

Javascript Trim Functions


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //full trim
  2. String.prototype.trim = function() {
  3. return this.replace(/^\s+|\s+$/g,"");
  4. }
  5.  
  6. //left trim
  7. String.prototype.ltrim = function() {
  8. return this.replace(/^\s+/,"");
  9. }
  10.  
  11. //right trim
  12. String.prototype.rtrim = function() {
  13. return this.replace(/\s+$/,"");
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.