Trim function, trims all leading and trailing spaces:

String.prototype.trim = function(){return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}

StartsWith to check if a string starts with a particular character sequecnce:

String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)}

EndsWith to check if a string ends with a particular character sequecnce:

String.prototype.endsWith = function(str) {return (this.match(str+"$")==str)}

All these functions once loaded will behave as built-in JavaScript functions. Here are few examples:

var myStr = “ Earth is a beautiful planet ”;
var myStr2 = myStr.trim(); //==“Earth is a beautiful planet”;
if (myStr2.startsWith(“Earth”)) // returns TRUE
if (myStr2.endsWith(“planet”)) // returns TRUE
if (myStr.startsWith(“Earth”)) // returns FALSE due to the leading spaces…
if (myStr.endsWith(“planet”)) // returns FALSE due to trailing spaces…