Vissu
Vissu

Reputation: 2043

'trim()' javascript function issues with Internet Explorer

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.

Upvotes: 1

Views: 3381

Answers (3)

nnnnnn
nnnnnn

Reputation: 150070

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,"");
}

Upvotes: 3

Misam
Misam

Reputation: 4389

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

Upvotes: 2

John K
John K

Reputation: 28917

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.

Upvotes: 2

Related Questions