Archive for the ‘JavaScript’ Category

JavaScript — Trim white space

July 23, 2007

Here is a way to trim the white space from a string in Javascript:

replace(/^\s+|\s+$/g, ”)

By removing |\s+$ it will do a left trim only, and by removing ^\s+| it will do a right trim only (g is no longer necessary).