| | Stumble It! | Add to Mixx! | | diigo it | | Slashdot |

Tuesday, August 18, 2009

Better JavaScript Trim

I'm continuing the trend of posting updated code with the new version of the trim function for JavaScript. JS doesn't include a trim() function by default so you have to build one yourself. Below is the snippet that I use to accomplish the task:
function trim(x) { return x = (x != null) ? x.replace(/^[\t\n\r\s]*|[\t\n\r\s]*$/g,"") : false ; }

0 comments: