日期:2014-05-16 浏览次数:20338 次
function test(){ var tt =" hoocy is very good boy"; tt.Trim(); alert(tt); } //去除字符串中间空格 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, ""); } function jtrim(s) { var i,b=0,e=s.length; for(i=0;i<s.length;i++) //去左空格 if(s.charAt(i)!=' '){b=i;break;} if(i==s.length) return ""; for(i=s.length-1;i>b;i--) // 去右空格 if(s.charAt(i)!=' '){e=i;break;} return s.substring(b,e+1); } function Jtrim(str) { var i = 0; var len = str.length; if ( str == "" ) return( str ); j = len -1; flagbegin = true; flagend = true; while (( flagbegin == true) && (i< len)) { if ( str.charAt(i) == " " ) { i=i+1; flagbegin=true; } else { flagbegin=false; } } while ((flagend== true) && (j>=0)) { if (str.charAt(j)==" ") { j=j-1; flagend=true; } else { flagend=false; } } if ( i > j ) return (""); trimstr = str.substring(i,j+1); return trimstr; } function IgnoreSpaces(Str){ var ResultStr = ""; Temp=Str.split(" "); //双引号之间是个空格; for(i = 0; i < Temp.length; i++) ResultStr +=Temp[i]; return ResultStr; }
?……
非正则判断输入是否数字
?
function checkNum(num) { var stringNum = "0123456789"; if("" === num || 0 === num.length) { return 1; } for(var i=0;i<num.length;i++) { if( -1 === stringNum.indexOf( num.charAt(i) ) ) { return 1; } } return 0; }?