In programming trim is a string manipulation function. It will remove the leading and trailing spaces. JavaScript does not provide the trim functionality by default. Best 3 sample i have provided below, same you can use for trimming the string using javascript.

Sample 1: Using Jquery trim: If you are using jquery, you can use the trim as shown below.

Sample 2: Another sample for javascript trim. It uses the regex function to trim the string.

Sample 3: Below function return the trimmed string.

Hopes above approaches will helps for newbies. If you have any good idea just add comments.

Similar Topics:


javascript trimjavascript trim clientid spaces