www.webdeveloper.com
Results 1 to 2 of 2

Thread: Javascript: Trim whitespaces from String

  1. #1
    Join Date
    May 2009
    Posts
    1

    Javascript: Trim whitespaces from String

    Hi,

    After getting a value in local var, how can I trim whitespaces in it.

    var temp = document.localform.<element-name>.value;

    Now how can I store trimmed value in temp.

    Thanks in Advance,
    Bala

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    add
    Code:
    String.prototype.trim=function () {return this.replace(/^\s+|\s+$/g, "");}
    somewhere before your posted code.

    then, its very easy to use:
    Code:
    var temp = document.localform.someInput.value.trim();
    this will be a standard string method in the next version of javascript, due to come out in late 2009.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles