1

trim() is not working in Internet Explorer(it's working properly in Chrome and Firefox). However I need to trim the value to prevent empty spaces.

user
  • 86,916
  • 18
  • 197
  • 190
vissu
  • 1,921
  • 7
  • 37
  • 52

3 Answers3

3

I don't think JavaScript provides trim() does it? Some browsers may implement it, and various libraries implement it.

You can add your own, something like this:

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
nnnnnn
  • 147,572
  • 30
  • 200
  • 241
2

If this turns out to be an IE bug, you can always implement your own workaround using RegEx in JavaScript like this left trim function sample - the sample can be expanded to trim both left and right sides. This Regex should work in all browsers.

Community
  • 1
  • 1
John K
  • 28,441
  • 31
  • 139
  • 229
2

Have a look @ this -> Trim not working in IE

Community
  • 1
  • 1
Misam
  • 4,320
  • 2
  • 25
  • 43
  • This one is easier by using **JQuery.trim(string);** and this solution is suitable for my application. **Because i am using JQuery** in my application. – vissu Apr 29 '11 at 07:27