Why don't you simply use JavaScript's trim():
str.trim() //Will work everywhere irrespective of any framework.
For compatibility with <IE9
use:
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
Found it Here