Posted on 2006-12-29 19:35
路易 閱讀(167)
評論(0) 編輯 收藏 所屬分類:
東方夜譚
??1
--------------
?函數(shù)檢索?
--------------
??2
trim函數(shù):?????????????????????????trim()?lTrim()?rTrim()
??3
校驗字符串是否為空:?????????????????checkIsNotEmpty(str)
??4
校驗字符串是否為整型:???????????????checkIsInteger(str)
??5
校驗整型最小值:????????????????????checkIntegerMinValue(str,val)
??6
校驗整型最大值:????????????????????checkIntegerMaxValue(str,val)?
??7
校驗整型是否為非負(fù)數(shù):???????????????isNotNegativeInteger(str)
??8
校驗字符串是否為浮點型:?????????????checkIsDouble(str)?
??9
校驗浮點型最小值:??????????????????checkDoubleMinValue(str,val)
?10
校驗浮點型最大值:??????????????????checkDoubleMaxValue(str,val)
?11
校驗浮點型是否為非負(fù)數(shù):?????????????isNotNegativeDouble(str)
?12
校驗字符串是否為日期型:?????????????checkIsValidDate(str)
?13
校驗兩個日期的先后:????????????????checkDateEarlier(strStart,strEnd)
?14
校驗字符串是否為email型:???????????checkEmail(str)
?15
?16
校驗字符串是否為中文:???????????????checkIsChinese(str)
?17
計算字符串的長度,一個漢字兩個字符:???realLength()
?18
校驗字符串是否符合自定義正則表達(dá)式:???checkMask(str,pat)
?19
得到文件的后綴名:???????????????????getFilePostfix(oFile)??
?20
--------------
?函數(shù)檢索?
--------------
?21
*/
?22
?23
/**/
/*
*
?24
*?added?by?LxcJie?2004.6.25
?25
*?去除多余空格函數(shù)
?26
*?trim:去除兩邊空格?lTrim:去除左空格?rTrim:?去除右空格
?27
*?用法:
?28
*?????var?str?=?"??hello?";
?29
*?????str?=?str.trim();
?30
*/
?31
String.prototype.trim?
=
?
function
()
?32
{
?33
????
return
?
this
.replace(
/
(
^
[s]
*
)
|
([s]
*
$)
/
g,?
""
);
?34
}
?35
String.prototype.lTrim?
=
?
function
()
?36
{
?37
????
return
?
this
.replace(
/
(
^
[s]
*
)
/
g,?
""
);
?38
}
?39
String.prototype.rTrim?
=
?
function
()
?40
{
?41
????
return
?
this
.replace(
/
([s]
*
$)
/
g,?
""
);
?42
}
?43
/**/
/*
*********************************?Empty?*************************************
*/
?44
/**/
/*
*
?45
*校驗字符串是否為空
?46
*返回值:
?47
*如果不為空,定義校驗通過,返回true
?48
*如果為空,校驗不通過,返回false???????????????參考提示信息:輸入域不能為空!
?49
*/
?50
function
?checkIsNotEmpty(str)
?51
{
?52
????
if
(str.trim()?
==
?
""
)
?53
????????
return
?
false
;
?54
????
else
?55
????????
return
?
true
;
?56
}
//
~~~
?57
/**/
/*
---------------------------------?Empty?--------------------------------------
*/
?58
/**/
/*
*********************************?Integer?************************************
*/
?59
/**/
/*
*
?60
*校驗字符串是否為整型
?61
*返回值:
?62
*如果為空,定義校驗通過,??????返回true
?63
*如果字串全部為數(shù)字,校驗通過,返回true
?64
*如果校驗不通過,??????????????返回false?????參考提示信息:輸入域必須為數(shù)字!
?65
*/
?66
function
?checkIsInteger(str)
?67
{
?68
????
//
如果為空,則通過校驗
?69
????
if
(str?
==
?
""
)
?70
????????
return
?
true
;
?71
????
if
(
/^
(
-?
)(d
+
)$
/
.test(str))
?72
????????
return
?
true
;
?73
????
else
?74
????????
return
?
false
;
?75
}
//
~~~
?76
/**/
/*
*
?77
*校驗整型最小值
?78
*str:要校驗的串。??val:比較的值
?79
*
?80
*返回值:
?81
*如果為空,定義校驗通過,????????????????返回true
?82
*如果滿足條件,大于等于給定值,校驗通過,返回true
?83
*如果小于給定值,????????????????????????返回false??????????????參考提示信息:輸入域不能小于給定值!
?84
*/
?85
function
?checkIntegerMinValue(str,val)
?86
{
?87
????
//
如果為空,則通過校驗
?88
????
if
(str?
==
?
""
)
?89
????????
return
?
true
;
?90
????
if
(
typeof
(val)?
!=
?
"
string
"
)
?91
????????val?
=
?val?
+
?
""
;
?92
????
if
(checkIsInteger(str)?
==
?
true
)
?93
????
{
?94
????????
if
(parseInt(str,
10
)
>=
parseInt(val,
10
))
?95
????????????
return
?
true
;
?96
????????
else
?97
????????????
return
?
false
;
?98
????}
?99
????
else
100
????????
return
?
false
;
101
}
//
~~~
102
/**/
/*
*
103
*校驗整型最大值
104
*str:要校驗的串。??val:比較的值
105
*
106
*返回值:
107
*如果為空,定義校驗通過,????????????????返回true
108
*如果滿足條件,小于等于給定值,校驗通過,返回true
109
*如果大于給定值,????????????????????????返回false???????參考提示信息:輸入值不能大于給定值!
110
*/
111
function
?checkIntegerMaxValue(str,val)
112
{
113
????
//
如果為空,則通過校驗
114
????
if
(str?
==
?
""
)
115
????????
return
?
true
;
116
????
if
(
typeof
(val)?
!=
?
"
string
"
)
117
????????val?
=
?val?
+
?
""
;
118
????
if
(checkIsInteger(str)?
==
?
true
)
119
????
{
120
????????
if
(parseInt(str,
10
)
<=
parseInt(val,
10
))
121
????????????
return
?
true
;
122
????????
else
123
????????????
return
?
false
;
124
????}
125
????
else
126
????????
return
?
false
;
127
}
//
~~~
128
/**/
/*
*
129
*校驗整型是否為非負(fù)數(shù)
130
*str:要校驗的串。
131
*
132
*返回值:
133
*如果為空,定義校驗通過,返回true
134
*如果非負(fù)數(shù),????????????返回true
135
*如果是負(fù)數(shù),????????????返回false???????????????參考提示信息:輸入值不能是負(fù)數(shù)!
136
*/
137
function
?isNotNegativeInteger(str)
138
{
139
????
//
如果為空,則通過校驗
140
????
if
(str?
==
?
""
)
141
????????
return
?
true
;
142
????
if
(checkIsInteger(str)?
==
?
true
)
143
????
{
144
????????
if
(parseInt(str,
10
)?
<
?
0
)
145
????????????
return
?
false
;
146
????????
else
147
????????????
return
?
true
;
148
????}
149
????
else
150
????????
return
?
false
;
151
}
//
~~~
152
/**/
/*
---------------------------------?Integer?--------------------------------------
*/
153
/**/
/*
*********************************?Double?***************************************
*/
154
/**/
/*
*
155
*校驗字符串是否為浮點型
156
*返回值:
157
*如果為空,定義校驗通過,??????返回true
158
*如果字串為浮點型,校驗通過,??返回true
159
*如果校驗不通過,??????????????返回false?????參考提示信息:輸入域不是合法的浮點數(shù)!
160
*/
161
function
?checkIsDouble(str)
162
{
163
????
//
如果為空,則通過校驗
164
????
if
(str?
==
?
""
)
165
????????
return
?
true
;
166
????
//
如果是整數(shù),則校驗整數(shù)的有效性
167
????
if
(str.indexOf(
"
.
"
)?
==
?
-
1
)
168
????
{
169
????????
if
(checkIsInteger(str)?
==
?
true
)
170
????????????
return
?
true
;
171
????????
else
172
????????????
return
?
false
;
173
????}
174
????
else
175
????
{
176
????????
if
(
/^
(
-?
)(d
+
)(.
{
1
}
)(d
+
)$
/
g.test(str))
177
????????????
return
?
true
;
178
????????
else
179
????????????
return
?
false
;
180
????}
181
}
//
~~~