Easy Effective and Simple Javacript Trim Function

By Ali Hammad Baig on 5:50 AM

Filed Under: , ,

// Removes leading white spaces

function LTrim( value ){
var re = /\s*((\S+\s*)*)/;
return value.replace(re, "$1");
}

// Removes ending white spaces


function RTrim( value ) {

var re = /((\s*\S+)*)\s*/;
return value.replace(re, "$1");
}

// Removes leading and ending white spaces

function trim( value ){

return LTrim(RTrim(value));
}

0 comments for this post

Post a Comment

Blog Widget by LinkWithin