String.prototype.reverse = function()   //// reverses this string by using the Array object's reverse method
{ return( this.split("").reverse().join("") ); }   // example:  str = str.reverse();


String.prototype.srchrepl = function(srchstr,replstr)	 //// text search/replace method
{ return( this.split(srchstr).join(replstr?replstr:"") ); }   // example:  str = str.srchrepl("x","y");


String.prototype.truncate = function(truncstr)   //// truncates this string at the first occurance of truncstr
{ return( (this.indexOf(truncstr) >= 0) ? this.substring(0,this.indexOf(truncstr)) : this ); }   // example:  str = str.truncate("x");


String.prototype.containsonly = function(validstr)    //// determines if this string contains only characters in validstr
{
	if ( !validstr ) return( false );             // example:  rc = str.containsonly("ABC123");
	var re = /([^\w\s])/gi;
	restr = "[" + validstr.toString().replace( re, "\\ /$1" ).srchrepl("\\ /","\\") + "]*";
	re = new RegExp( restr, "gi" );
	return( re.exec(this)[0] == this );
}


String.prototype.containsall = function(validstr)   //// determines if this string contains all characters in validstr
{ return( validstr ? validstr.containsonly(this) : false ); }  // example:  rc = str.containsall("ABC123");


String.prototype.isalpha = function()	//// determines if this string contains only alphabetic characters (A-Z,a-z)
{ return( this.containsonly("ABCDEFGHIJKLMNOPQRSTUVWXYZ") ); }  // example:  rc = str.isalpha();


String.prototype.isnumeric = function()   //// determines if this string contains only numeric characters (0-9)
{ return( this.containsonly("0123456789") ); }  // example:  rc = str.isnumeric();


String.prototype.isalphanumeric = function()   //// determines if this string contains only alphanumeric characters (A-Z,a-z,0-9)
{ return( this.containsonly("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") ); }  // example:  rc = str.isalphanumeric();


String.prototype.iswhite = function()	//// determines if this string contains only white space
{ return( ( this != "" ) && this.containsonly(" \t\r\n\f\v" ) ); }  // example:  rc = str.iswhite();


String.prototype.rtrim = function()    //// trims white space off the tail of this string
{ return( (ar=/(^[\s\S]*\S+)\s*$/.exec(this)) ? ar[1] : "" ); }  // example:  str = str.rtrim();


String.prototype.ltrim = function()    //// trims white space off the head of this string
{ return( (ar=/^\s*([\s\S]*$)/.exec(this)) ? ar[1] : "" ); }  // example:  str = str.ltrim();


String.prototype.trim = function()    //// trims white space off both ends of this string
{ return( (ar=/^\s*([\s\S]*\S+)\s*$/.exec(this)) ? ar[1] : "" ); }  // example:  str = str.trim();

////////////// testing ... this works different than the above function with this string: " \n "
String.prototype.trim2 = function()    //// trims white space off both ends of this string
{ return( this.replace(/^\s*([\s\S]*\S+)\s*$/,'$1') ); }  // example:  str = str.trim2();


String.prototype.rpad = function(len)   //// adds spaces to the tail of this string until this.length == len
{ return( this.length < len ? (this+" ").rpad(len) : this ); }  // example:  str = str.rpad(8);


String.prototype.lpad = function(len)   //// adds spaces to the head of this string until this.length == len
{ return( this.length < len ? (" "+this).lpad(len) : this ); }  // example:  str = str.lpad(8);


String.prototype.pad = function(len)   //// adds spaces to both ends of this string until this.length == len
{ return( this.length < len-1 ? (" "+this+" ").pad(len) : this.rpad(len) ); }  // example:  str = str.pad(8);


String.prototype.isempty = function()	//// determines if this string is empty
{ return( this.trim().length==0 ); }  // example:  rc = str.isempty();


String.prototype.isemail = function()	//// determines if this string is at least 5 chars long, contains @ and .
{ return( this.trim().length>5 && this.containsall(".@") ); }  // example:  rc = str.isemail();



