...

View Full Version : deleting white spaces



dark0s
07-16-2010, 08:56 AM
How can I to delete white spaces around parameter that I to pass with HTML forms.
For example, if I have 'firstname lastname ' or ' firstname lastname', exist it a builtin function in javascript to obtian 'firstname lastname'?

savio

Kor
07-16-2010, 09:02 AM
You may use a trim function (based on Regular Expressions)


function alltrim(str) {
return str.replace(/^\s+|\s+$/g, '');
}

mrhoo
07-16-2010, 10:45 PM
New versions of Safari, Chrome , Opera and Firefox have a native string trim,
and IE9 does, as well. You could substitute Kor's method, if trim is not already defined


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum