JQuery: utility functions II – trimming strings
In this post we’re going to talk about the helper trim method. This is really a simple function which removes any leading or trailing whitespaces from the passed string. Notice that the method uses regular expressions and considers white spaces as any char that matches spaces, form feed, new line, return, tab and vertical tab characters.
Using the function is really simple, as you can see from this snippet:
var someText = " Hello there";
alert("-" + $.trim(someText) + "-");
And that’s it. Keep tuned for more on JQuery.