mhk wrote on 16 jan 2005 in comp.lang.javascript
:
Read the Group FAQ, it has snippets of code for emulating Trim as
Javascript has no native Trim()
*******************************************
the code in your FAQ doesnt handle enter keys.
Whose FAQ?
Keys are not part of a string, so what do you mean|?
this one is much better.
found on internet.
// Trim Function
// --------------
String.prototype.trim = function()
{
// skip leading and trailing whitespace
// and return everything in between
var x=this;
x=x.replace(/^\s*(.*)/, "$1");
x=x.replace(/(.*?)\s*$/, "$1");
return x;
}
a bit overdone regex, methinks.
x = x.replace(/^\s*/, "");
x = x.replace(/\s*$/, "");
or
x = x.replace(/^\s*(.*?)\s*$/, "$1");
Problem with your and this last one is,
that older js may not know lookahead "?"
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)