trim function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • romepatel
    New Member
    • Nov 2009
    • 31

    trim function

    Hi,
    I am newbie to the javascript
    I need to validate the text box,
    i want to enter the blank value in the text box,
    so in order to remove white spaces, i had used trim function,
    but it is not effected and it gives me javascript error in IE6,

    Even the example of w3school is also not working in IE6.

    Please help me out....!!!!

    Thanks in advance
  • hitendrap
    New Member
    • Sep 2009
    • 9

    #2
    Code:
    function trimStr(value)
    {
    	return value.replace(/^\s+|\s+$/g, '')
    }
    Last edited by Dormilich; Feb 5 '10, 01:31 PM. Reason: Please use [code] tags when posting code

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      use native methods, if available.
      Code:
      function trimStr(value)
      {
          if (value.trim) {
              return value.trim();
          }
          return value.replace(/^\s+|\s+$/g, '');
      }

      Comment

      Working...