Web Analytics Made Easy -
StatCounter how to trim a string - CodingForum

Announcement

Collapse
No announcement yet.

how to trim a string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to trim a string

    Hi,

    Is there a trim() function in Javascript? I am trying to find one, can anybody give me a hand?

    Henry

  • #2
    String.prototype.trim = function() {
    return this.replace(/^\s+/,'').replace(/\s+$/,'');
    }

    Now:

    ' hello '.trim() == 'hello'

    jasonkarldavis.com

    Comment


    • #3
      trim a string

      Hi,

      How to call the function with a event handler in an textbox


      Thanks
      Rama

      Comment


      • #4
        Umm, assuming that code was declared elsewhere in the page:

        onblur="this.value = this.value.trim()"
        jasonkarldavis.com

        Comment

        Working...
        X