Jessica Posted February 15, 2007 Share Posted February 15, 2007 Is there a simple function to remove whitespace from the front and end of a string? Can't find one in the docs... Edit: Today is my day for finding my own answers function LTrim( value ) { var re = /\s*((\S+\s*)*)/; return value.replace(re, "$1"); } // Removes ending whitespaces function RTrim( value ) { var re = /((\s*\S+)*)\s*/; return value.replace(re, "$1"); } // Removes leading and ending whitespaces function trim( value ) { return LTrim(RTrim(value)); } Quote Link to comment Share on other sites More sharing options...
ozfred Posted February 15, 2007 Share Posted February 15, 2007 Is there a simple function to remove whitespace from the front and end of a string? Can't find one in the docs... Edit: Today is my day for finding my own answers <URL: http://www.jibbering.com/faq/#FAQ4_16 > Quote Link to comment Share on other sites More sharing options...
fenway Posted February 15, 2007 Share Posted February 15, 2007 Not sure about that regex you're using... I've always used /^\s+|\s+$/g Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.