You might find this interesting:
We made a javascript function that trims leading/trailing spaces from field values, but found it did not include the nonbreaking space character (nbsp;) when it appeared.
Before fixing it, our function looked like this:
-------------------------------------
String.prototype.Trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
-------------------------------------
After discovering that values that included nbsp; were not getting trimmed, I found the following to be true:
nbsp; = chr(160) = xA0
So have now modified the Trim function to read:
-------------------------------------
String.prototype.Trim = function()
{
return this.replace(/(^{\s\xA0#}*)|({\s\xA0#}*$)/g, "");
}
-------------------------------------
(Please note that I used CURLY BRACKETS in the example above, but if you use this, use SQUARE BRACKETS -- they just wouldn't display on this page when I typed them in...)
And it works!! FYI, to clean field values, our javascript code calls it this way:
document.forms[0].myField.value.Trim();
Hope this helps someone,
Susan Henesy
Originally posted as a Categorized Answer.