Javascript Equivalent of PHP’s trim function

Trim function in PHP can remove whitespace from the beginning and end of a string.

Javascript do not have this function, but is easy to made one.

// remove space in a string 
function trim(str)
	if(!str || typeof str != 'string')
		return null;
	return str.replace('/^\s+|\s+$/g', '');
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

Comments are closed.