var a = "hello"; var b = ",world"; var c = a.concat(b); alert(c); //c = "hello,world"
var index1 = a.indexOf("l");
//index1 = 2
var index2 = a.indexOf("l",3);
//index2 = 3
var get_char = a.charAt(0); //get_char = "h"
var index1 = lastIndexOf('l');
//index1 = 3
var index2 = lastIndexOf('l',2)
//index2 = 2
var re = new RegExp(/^w+$/); var is_alpha1 = a.match(re); //is_alpha1 = "hello" var is_alpha2 = b.match(re); //is_alpha2 = null
var sub_string1 = a.substring(1); //sub_string1 = "ello" var sub_string2 = a.substring(1,4); //sub_string2 = "ell"
var sub_string1 = a.substr(1); //sub_string1 = "ello" var sub_string2 = a.substr(1,4); //sub_string2 = "ello"
var result1 = a.replace(re,"Hello"); //result1 = "Hello" var result2 = b.replace(re,"Hello"); //result2 = ",world"
var index1 = a.search(re); //index1 = 0 var index2 = b.search(re); //index2 = -1
var sub_string1 = a.slice(1); //sub_string1 = "ello" var sub_string2 = a.slice(1,4); //sub_string2 = "ell"
var arr1 = a.split("");
//arr1 = [h,e,l,l,o]
var len = a.length(); //len = 5
var lower_string = a.toLowerCase(); //lower_string = "hello"
var upper_string = a.toUpperCase(); //upper_string = "HELLO"
String.prototype.LTrim = function()
{
return this.replace(/(^s*)/g, "");
}
String.prototype.Rtrim = function()
{
return this.replace(/(s*$)/g, "");
}
String.prototype.Trim = function()
{
return this.replace(/(^s*)|(s*$)/g, "");
}
String.prototype.Left = function(len)
{
if(isNaN(len)||len==null)
{
len = this.length;
}
else
{
if(parseInt(len)<0||parseInt(len)>this.length)
{
len = this.length;
}
}
return this.substr(0,len);
}
String.prototype.Right = function(len)
{
if(isNaN(len)||len==null)
{
len = this.length;
}
else
{
if(parseInt(len)<0||parseInt(len)>this.length)
{
len = this.length;
}
}
return this.substring(this.length-len,this.length);
}
String.prototype.Mid = function(start,len)
{
return this.substr(start,len);
}
String.prototype.InStr = function(str)
{
if(str==null)
{
str = "";
}
return this.indexOf(str);
}
String.prototype.InStrRev = function(str)
{
if(str==null)
{
str = "";
}
return this.lastIndexOf(str);
}
String.prototype.LengthW = function()
{
return this.replace(/[^x00-xff]/g,"**").length;
}
String.prototype.isIP = function()
{
var reSpaceCheck = /^(d+).(d+).(d+).(d+)$/;
if (reSpaceCheck.test(this))
{
this.match(reSpaceCheck);
if (RegExp.$1 <= 255 && RegExp.$1 >= 0
&& RegExp.$2 <= 255 && RegExp.$2 >= 0
&& RegExp.$3 <= 255 && RegExp.$3 >= 0
&& RegExp.$4 <= 255 && RegExp.$4 >= 0)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
String.prototype.isLongDate = function()
{
var r = this.replace(/(^s*)|(s*$)/g, "").match(/^(d{1,4})(-|/)(d{1,2})2(d{1,2}) (d{1,2}):(d{1,2}):(d{1,2})$/);
if(r==null)
{
return false;
}
var d = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
}
String.prototype.isShortDate = function()
{
var r = this.replace(/(^s*)|(s*$)/g, "").match(/^(d{1,4})(-|/)(d{1,2})2(d{1,2})$/);
if(r==null)
{
return false;
}
var d = new Date(r[1], r[3]-1, r[4]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}
String.prototype.isDate = function()
{
return this.isLongDate()||this.isShortDate();
}
String.prototype.isMobile = function()
{
return /^0{0,1}13[0-9]{9}$/.test(this);
}
String.prototype.isEmail = function()
{
return /^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$/.test(this);
}
String.prototype.isZipCode = function()
{
return /^[\d]{6}$/.test(this);
}
String.prototype.existChinese = function()
{
//[u4E00-u9FA5]為漢字﹐[uFE30-uFFA0]為全角符號
return /^[x00-xff]*$/.test(this);
}
String.prototype.isFileName = function()
{
return !/[\/*?|:"<>]/g.test(this);
}
String.prototype.isUrl = function()
{
return /^http[s]?://([w-]+.)+[w-]+([w-./?%&=]*)?$/i.test(this);
}
String.prototype.isIDCard = function()
{
var iSum=0;
var info="";
var sId = this;
var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙 江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖 北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"};
if(!/^d{17}(d|x)$/i.test(sId))
{
return false;
}
sId=sId.replace(/x$/i,"a");
//非法地区
if(aCity[parseInt(sId.substr(0,2))]==null)
{
return false;
}
var sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
var d=new Date(sBirthday.replace(/-/g,"/"))
//非法生日
if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))
{
return false;
}
for(var i = 17;i>=0;i--)
{
iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11);
}
if(iSum!=1)
{
return false;
}
return true;
}
String.prototype.isPhoneCall = function()
{
return /(^[0-9]{3,4}-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^([0-9]{3,4})[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/.test(this);
}
String.prototype.isNumeric = function(flag)
{
//验证是否是数字
if(isNaN(this))
{
return false;
}
switch(flag)
{
case null: //数字
case "":
return true;
case "+": //正数
return /(^+?|^d?)d*.?d+$/.test(this);
case "-": //负数
return /^-d*.?d+$/.test(this);
case "i": //整数
return /(^-?|^+?|d)d+$/.test(this);
case "+i": //正整数
return /(^d+$)|(^+?d+$)/.test(this);
case "-i": //负整数
return /^[-]d+$/.test(this);
case "f": //浮点数
return /(^-?|^+?|^d?)d*.d+$/.test(this);
case "+f": //正浮点数
return /(^+?|^d?)d*.d+$/.test(this);
case "-f": //负浮点数
return /^[-]d*.d$/.test(this);
default: //缺省
return true;
}
}
String.prototype.IsColor = function()
{
var temp = this;
if (temp=="") return true;
if (temp.length!=7) return false;
return (temp.search(/#[a-fA-F0-9]{6}/) != -1);
}
String.prototype.toCase = function()
{
var tmp = "";
for(var i=0;i<this.length;i++)
{
if(this.charCodeAt(i)>0&&this.charCodeAt(i)<255)
{
tmp += String.fromCharCode(this.charCodeAt(i)+65248);
}
else
{
tmp += String.fromCharCode(this.charCodeAt(i));
}
}
return tmp
}
String.prototype.toHtmlEncode = function()
{
var str = this;
str=str.replace(/&/g,"&");
str=str.replace(/</g,"<");
str=str.replace(/>/g,">");
str=str.replace(/'/g,"'");
str=str.replace(/"/g,""");
str=str.replace(/n/g,"<br>");
str=str.replace(/ /g," ");
str=str.replace(/t/g," ");
return str;
}
String.prototype.toDate = function()
{
try
{
return new Date(this.replace(/-/g, "/"));
}
catch(e)
{
return null;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有