Jump to content

JS equiv of PHP's trim()?


Jessica

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.