JavaScript字符串函数大全Word下载.docx

上传人:b****2 文档编号:5830714 上传时间:2023-05-05 格式:DOCX 页数:38 大小:29.64KB
下载 相关 举报
JavaScript字符串函数大全Word下载.docx_第1页
第1页 / 共38页
JavaScript字符串函数大全Word下载.docx_第2页
第2页 / 共38页
JavaScript字符串函数大全Word下载.docx_第3页
第3页 / 共38页
JavaScript字符串函数大全Word下载.docx_第4页
第4页 / 共38页
JavaScript字符串函数大全Word下载.docx_第5页
第5页 / 共38页
JavaScript字符串函数大全Word下载.docx_第6页
第6页 / 共38页
JavaScript字符串函数大全Word下载.docx_第7页
第7页 / 共38页
JavaScript字符串函数大全Word下载.docx_第8页
第8页 / 共38页
JavaScript字符串函数大全Word下载.docx_第9页
第9页 / 共38页
JavaScript字符串函数大全Word下载.docx_第10页
第10页 / 共38页
JavaScript字符串函数大全Word下载.docx_第11页
第11页 / 共38页
JavaScript字符串函数大全Word下载.docx_第12页
第12页 / 共38页
JavaScript字符串函数大全Word下载.docx_第13页
第13页 / 共38页
JavaScript字符串函数大全Word下载.docx_第14页
第14页 / 共38页
JavaScript字符串函数大全Word下载.docx_第15页
第15页 / 共38页
JavaScript字符串函数大全Word下载.docx_第16页
第16页 / 共38页
JavaScript字符串函数大全Word下载.docx_第17页
第17页 / 共38页
JavaScript字符串函数大全Word下载.docx_第18页
第18页 / 共38页
JavaScript字符串函数大全Word下载.docx_第19页
第19页 / 共38页
JavaScript字符串函数大全Word下载.docx_第20页
第20页 / 共38页
亲,该文档总共38页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

JavaScript字符串函数大全Word下载.docx

《JavaScript字符串函数大全Word下载.docx》由会员分享,可在线阅读,更多相关《JavaScript字符串函数大全Word下载.docx(38页珍藏版)》请在冰点文库上搜索。

JavaScript字符串函数大全Word下载.docx

6.Left(x,n):

返回字符串x左边n个字符(对应Right(x,n))

7。

Mid:

读取字符串x中间的字符

v=mid(x,n,m)

8。

LTrim(x),RTim(x),Trim(x)去空白字符

9.Replace:

字符串取代

v=Replace(x,s,r)

x="

isawasawasaw"

v=replace(x,"

saw"

so"

v="

isoasoaso"

10.Split:

字符串分割

v=split(s[,d])

v=split("

iis6.0,"

'

"

iis6.0"

v

(2)="

11.StrReverse:

反转字符串

v=strreverse("

gnawjk"

12.UCase(x),LCase(x):

变换英文字母的大小写

hello,VB中文!

v=UCase(x)'

HELLO,VB中文!

 

1.取出日期时间

-1)DateValue(x),TimeValue(x)

v=DateValue(x):

取出的“日期”部分

   v=timevalue(x)'

类上

-2)Year(x),Month(x),Day(x)

v=Year(x)

   v=Month(x)

   v=Day(x)

   Hour(x),Minute(x),Second(x):

取出时,分,秒

-3)DateSerial(Y,M,D):

合并年、月、日成为日期

v=DateSerial(1996,10,5)'

v=1996/10/5

   TimeSerial(H,M,S):

合并时、分、秒成为时间

2.Now:

读取系统日期时间

v=now

3.Timer:

从凌晨12:

00:

00AM起所经过的秒数

v=timer

4.DatePart(p,x):

取出年、月、日等各部分的数值

DimX=#2/10/199616:

45:

30#

v=DatePart("

yyyy"

X)'

v=1996年

m"

v=2月

d"

v=10日

h"

v=16时

n"

v=45分

s"

v=30秒

q"

v=1季(第一季,春季)

y"

v=41天(1996年的第41天)

ww"

v=6周(1996年的第6周)

w"

v=7(第6周的第7天,即星期六)

DateAdd(p,n,x):

加减若干时间后的新日期时间

v=DateAdd(p,n,x)'

p值同上如:

、"

Dimx=#1/31/199616:

v=dateadd("

-3,x)'

减3年,v=1993/1/3116:

30

6.DateDiff(p,x1,x2):

计算两日期时间的差值'

p值同上

dimx1=#12/31/199616:

x2=#2/10/19979:

30:

50#

v=datediff("

x1,x2)'

v=1年 

FormatDateTime:

日期时间的格式化

v=formatdateyime(x[,日期格式])

日期格式值:

DateFormat.GeneralDate 、 DateFormat.LongDate、

DateFotmat.ShortDate、DateFormat.LongTime、DateFormat.ShortTime

8.MonthName:

返回月份名称

v=monthname(5)'

五月"

9.WeekDayName:

返回星期名称 ’用法同8.

/*

******************************************

字符串函数扩充 

*/

===========================================

//去除左边的空格

String.prototype.LTrim=function()

{

returnthis.replace(/(^\s*)/g,"

);

//去除右边的空格

String.prototype.Rtrim=function()

returnthis.replace(/(\s*$)/g,"

//去除前后空格

String.prototype.Trim=function()

returnthis.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)

returnthis.substr(0,len);

//得到右边的字符串

String.prototype.Right=function(len)

returnthis.substring(this.length-len,this.length);

//得到中间的字符串,注意从0开始

String.prototype.Mid=function(start,len)

returnthis.substr(start,len);

//在字符串里查找另一字符串:

位置从0开始

String.prototype.InStr=function(str)

if(str==null)

str="

;

returnthis.indexOf(str);

//在字符串里反向查找另一字符串:

位置0开始

String.prototype.InStrRev=function(str)

returnthis.lastIndexOf(str);

//计算字符串打印长度

String.prototype.LengthW=function()

returnthis.replace(/[^\x00-\xff]/g,"

**"

).length;

//是否是正确的IP地址

String.prototype.isIP=function()

varreSpaceCheck=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;

if(reSpaceCheck.test(this))

this.match(reSpaceCheck);

if(RegExp.$1<

=255&

&

RegExp.$1>

=0 

RegExp.$2<

RegExp.$2>

RegExp.$3<

RegExp.$3>

RegExp.$4<

RegExp.$4>

=0) 

returntrue;

returnfalse;

//是否是正确的长日期

String.prototype.isLongDate=function()

varr=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)

vard=newDate(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()

).match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);

vard=newDate(r[1],r[3]-1,r[4]);

d.getDate()==r[4]);

//是否是正确的日期

String.prototype.isDate=function()

returnthis.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()

variSum=0;

varinfo="

varsId=this;

varaCity={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))

sId=sId.replace(/x$/i,"

a"

//非法地区

if(aCity[parseInt(sId.substr(0,2))]==null)

varsBirthday=sId.substr(6,4)+"

-"

+Number(sId.substr(10,2))+"

+Number(sId.substr(12,2));

vard=newDate(sBirthday.replace(/-/g,"

/"

))

//非法生日

if(sBirthday!

=(d.getFullYear()+"

+(d.getMonth()+1)+"

+d.getDate()))

for(vari=17;

i>

=0;

i--) 

iSum+=(Math.pow(2,i)%11)*parseInt(sId.charAt(17-i),11);

if(iSum%11!

=1)

//是否是有效的电话号码(中国)

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))

switch(flag)

casenull:

//数字

case"

+"

//正数

return/(^\+?

|^\d?

)\d*\.?

\d+$/.test(this);

//负数

return/^-\d*\.?

i"

//整数

return/(^-?

|^\+?

|\d)\d+$/.test(this);

+i"

//正整数

return/(^\d+$)|(^\+?

\d+$)/.test(this);

-i"

//负整数

return/^[-]\d+$/.test(this);

f"

//浮点数

)\d*\.\d+$/.test(this);

+f"

//正浮点数

-f"

//负浮点数

return/^[-]\d*\.\d$/.test(this);

default:

//缺省

=========

//是否是颜色(#FFFFFF形式)

String.prototype.IsColor=function()

vartemp=this;

if(temp=="

)returntrue;

if(temp.length!

=7)returnfalse;

return(temp.search(/\#[a-fA-F0-9]{6}/)!

=-1);

//转换成全角

String.prototype.toCase=function()

vartmp="

for(var

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2