Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 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
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    String.prototype.trim = function() {
    return this.replace(/^\s+/,'').replace(/\s+$/,'');
    }

    Now:

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


  • #3
    New Coder
    Join Date
    Jun 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    trim a string

    Hi,

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


    Thanks
    Rama

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Umm, assuming that code was declared elsewhere in the page:

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


  •  

    Posting Permissions

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