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)); } Link to comment https://forums.phpfreaks.com/topic/38587-js-equiv-of-phps-trim/ 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 > Link to comment https://forums.phpfreaks.com/topic/38587-js-equiv-of-phps-trim/#findComment-185198 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 Link to comment https://forums.phpfreaks.com/topic/38587-js-equiv-of-phps-trim/#findComment-185521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.