String.prototype.Trim = function(){ return this.replace(/(^\s*)|(\s*$)/g, ""); } String.prototype.LTrim = function() { return this.replace(/(^\s*)/g, ""); } String.prototype.RTrim = function() { return this.replace(/(\s*$)/g, ""); } //现在JS也可以直接调用TRIM,LTRIM,RTRIM来去除多余的空格的。 //简单使用方法 去除左右空格 document.form1('name').value.Trim()=='';
//一个汉字两个字符 String.prototype.realLength = function() { return this.replace(/[^\x00-\xff]/g, "**").length; }