Trimming Spaces in JavaScript Using a Regular Expression

One simple way of trimming a string is to make use of a powerful regular expression?as opposed to iterating and removing the space characters one by one. To see how this works, save the code below as an .htm file, and then load the file into IE. Click in the text field and then tab out of it to see the code in action.

<html>    Trim String    

The JS code in the TrimString function replaces the space(s) character (identified as s in the regular expression) with a blank or empty character.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: