From: FAQ server on
-----------------------------------------------------------------------
FAQ Topic - How do I trim whitespace?
-----------------------------------------------------------------------

ECMAScript 5 defines `String.prototype.trim`. Where not supported,
it can be added as a function that uses a regular expression:

if(!String.prototype.trim) {
String.prototype.trim = function() {
return String(this).replace(/^\s+|\s+$/g, "");
};
}

Implementations are inconsistent with `\s`. For example,
some implementations, notably JScript 5.8 and Safari 2, do not match `\xA0`
(no-break space), among others.

A more consistent approach would be to create a character class
that defines the characters to trim.

<URL: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp>
<URL: http://thinkweb2.com/projects/prototype/whitespace-deviations/>
<URL: https://developer.mozilla.org/en/Firefox_3.1_for_developers>
<URL: http://docs.sun.com/source/816-6408-10/regexp.htm>
<URL: http://msdn.microsoft.com/en-us/library/6wzad2b2%28VS.85%29.aspx>
<URL: http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/c7010139217600c3/31092c5eb99625d0?#31092c5eb99625d0>
<URL: http://unicode.org/Public/UNIDATA/PropList.txt>


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.

From: Dr J R Stockton on
In comp.lang.javascript message <4c5c93fa$0$273$14726298(a)news.sunsite.dk
>, Fri, 6 Aug 2010 23:00:02, FAQ server <javascript(a)dotinternet.be>
posted:

>
>Implementations are inconsistent with `\s`. For example,
>some implementations, notably JScript 5.8 and Safari 2, do not match `\xA0`
>(no-break space), among others.
>

While IE users may be reluctant to upgrade from, say, IE6 [*], I doubt
whether there are enough Safari 2 users left to justify mentioning it -
especially as IE8 serves as an example.

<URL:http://www.merlyn.demon.co.uk/js-valid.HTM#RsT> in IE8 :

Scripting is :- JScript 5.8.22960
In this browser, working on string All :

\s matches : 6 :
[ 0009 000a 000b 000c 000d 0020 ]

Remember that \w is defective in IE8, matching also dotted-I, in both
JScript and VBscript.


[*] <http://www.telegraph.co.uk/technology/microsoft/7928193/Upgrading-
from-IE6-is-too-complicated-says-Government.html>

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE8 FF3 Op10 Sf4 Cr4
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.