...

View Full Version : how to trim a string



henrysu
07-10-2002, 01:18 AM
Hi,

Is there a trim() function in Javascript? I am trying to find one, can anybody give me a hand?

Henry

jkd
07-10-2002, 01:32 AM
String.prototype.trim = function() {
return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

Now:

' hello '.trim() == 'hello'

:)

rama
07-10-2002, 05:00 AM
Hi,

How to call the function with a event handler in an textbox


Thanks
Rama

jkd
07-10-2002, 05:01 AM
Umm, assuming that code was declared elsewhere in the page:

onblur="this.value = this.value.trim()"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum