1//檢查空串
2function isEmpty(str){
3 if((str == null)||(str.length == 0)) return (true);
4 else return(false);
5}
6
7//檢查是否未數字
8function isDigit(theNum){
9var theMask = "0123456789";
10if (isEmpty(theNum)) return(false);
11else if(theMask.indexOf(theNum) == -1) return(false);
12return(true);
13}
14
15//去掉左空格
16function trimLeft(str){
17if(str.charAt(0) == " "){
18str = str.slice(1);
19str = trimLeft(str);
20}
21 return str;
22}
23
24//去掉右空格
25function trimRight(str){
26if(str.charAt( str.length - 1 ) == " "){
27str = str.slice(0,str.length - 1);
28str = trimRight(str);
29}
30 return str;
31}
32
33//去掉左右空格
34function trim(str){
35return trimLeft(trimRight(str));
36}
37
38//檢查是否是int
39function isInt(str){
40if(str==""){
41return (false);
42}
43else{
44for(i=0;i<str.length;i++){
45var chr = str.charAt(i);
46if(!(chr>='0' && chr<='9')){
47return (false);
48}
49}
50}
51return (true);
52}
53
54//檢查str是小數,它的整數部分不多于i位,小數部分不多于j位
55function isDecimalNoMsg(str,i,j){
56var dot = str.indexOf(".");
57var dot_last = str.lastIndexOf(".");
58var str_f = "";
59var str_b = "";
60if ( dot != -1 ){
61str_f = str.substring(0,dot);
62} else {
63str_f = str;
64}
65
66if ( dot_last != -1 ){
67str_b = str.substring(dot+1);
68} else {
69str_b = str;
70}
71
72if( isInt( str_f ) == false ){
73//alert(strMsg);
74return false;
75} else if ( isInt( str_b ) == false ){
76//alert(strMsg);
77return false;
78} else if ( dot != dot_last ){
79//alert(strMsg);
80return false;
81} else if(dot==0 || dot_last==0){
82//alert(strMsg);
83return false;
84}
85
86if(str_f.length>i){
87//alert(strMsg);
88return false;
89}
90if(dot!=-1 && str_b.length>j){
91//alert(strMsg);
92return false;
93}
94return true;
95}
96
97//檢查日期格式Format: 99999999)
98function judgeDateFormat(dateStr){
99 var re,r;
100 re = /\d{8}/;
101 r = dateStr.match(re);
102 return(r);
103}
104
105//檢查時間格式(Format: 999999)
106function judgeTimeFormat(timeStr){
107 var re,r;
108 re = /\d{6}/;
109 r = timeStr.match(re);
110 return(r);
111}
112
113//檢查日期是否合法(Format: YYYYMMDD).
114function validateDate(theStr){
115 if(theStr.length!=8){
116 return (false);
117 } else {
118 if(theStr=="99999999")
119 return (true);
120 var y = theStr.substring(0,4);
121 var m = theStr.substring(4,6);
122 var d = theStr.substring(6,8);
123 var maxDays = 31;
124 if(isInt(m)==false||isInt(d)==false||isInt(y)==false){
125 return(false);
126 }
127 else if (y.length < 4){ return(false);}
128 else if (!isBetween(m,1,12)){ return(false);}
129 if(m.length!=2){ return(false);}
130 else if (m==4||m==6||m==9||m==11)maxDays = 30;
131 else if (m==2){
132 if(y%4>0)maxDays = 28;
133 else if(y%100==0&&y%400>0)maxDays = 28;
134 else maxDays = 29;
135 }
136 if(isBetween(d,1,maxDays)==false){ return(false);}
137 if(d.length!=2){ return(false);}
138 return(true);
139
140 }
141}
142
143//檢查時間是否合法(Format: HHMMSS).
144function validateTime(theStr){
145 if(theStr.length!=6){
146 return (false);
147 } else {
148 if(theStr == "240000"){
149 return (true);
150 }
151 var h = theStr.substring(0,2);
152 var m = theStr.substring(2,4);
153 var s = theStr.substring(4,6);
154 if(isInt(h)==false||isInt(m)==false||isInt(s)==false){
155 return(false);
156 }
157 else if (h.length < 2){ return(false);}
158 else if (!isBetween(h,0,23)){ return(false);}
159 else if (!isBetween(m,0,59)){ return(false);}
160 else if (!isBetween(s,0,59)){ return(false);}
161 return true;
162 }
163}
164//檢查str包含漢字時最大長度不大于maxLen
165function ChineseLenLimit( str, maxLen){
166 var Strs = str;
167 var strlength=0;
168 var i;
169 for ( i=0;i<str.length;i++) {
170 if(str.charCodeAt(i)>=1000)
171 strlength += 2;
172 else
173 strlength += 1;
174 }
175 if ( strlength > maxLen ){
176 return false;
177 }
178 return true;
179
180}
181
182//檢查val在lo與hi之間
183function isBetween(val,lo,hi){
184 if ((val < lo) || (val > hi)){ return(false);}
185 else { return(true);}
186}
187
188// 檢查charC是‘0’~‘9’
189function chkChar(charC) {
190if (charC == null || charC.length == 0) {
191return false;
192}
193if (charC == '0')return true;
194if (charC == '1')return true;
195if (charC == '2')return true;
196if (charC == '3')return true;
197if (charC == '4')return true;
198if (charC == '5')return true;
199if (charC == '6')return true;
200if (charC == '7')return true;
201if (charC == '8')return true;
202if (charC == '9')return true;
203return false;
204}
205
206// 檢查intI是正整數
207function chkInt(intI) {
208if (intI == null || intI.length == 0) {
209return false;
210}
211for(var i=0;i<intI.length;i++) {
212if (!chkChar(intI.charAt(i))) {
213return false;
214}
215}
216if (intI.charAt(0) == '0') {
217return false;
218}
219return true;
220}
221// 檢查numN是數字
222function chkNumber(numN) {
223if (numN == null || numN.length == 0) {
224return false;
225}
226for(var i=0;i<numN.length;i++) {
227if (!chkChar(numN.charAt(i))) {
228return false;
229}
230}
231if (numN.length > 1 && numN.charAt(0) == '0') {
232return false;
233}
234return true;
235}
236// 檢查錢數小數點后最多2位
237function chkAmount(amtA) {
238if (amtA == null || amtA.length == 0) {
239return false;
240}
241var amtArray = new Array();
242amtArray = amtA.split(".");
243if (amtArray.length > 2) {
244return false;
245}
246if (amtArray.length == 1) {
247if (!chkNumber(amtArray[0])) {
248return false;
249}
250return true;
251}
252if (!chkNumber(amtArray[0])) {
253return false;
254}
255if (amtArray[1].length > 2) {
256return false;
257}
258for(var i=0;i<amtArray[1].length;i++) {
259if (!chkChar(amtArray[1].charAt(i))) {
260return false;
261}
262}
263return true;
264}
265//檢查身份證
266function checkAgentId(agentId){
267 if (agentId.length==10){
268 if (((agentId.charAt(0)=="A") && (agentId.charAt(1)=="A"))||((agentId.charAt(0)=="A") && (agentId.charAt(1)=="Z"))){
269 return true;
270}else{
271 checknum1=((agentId.charAt(0)>="A") && (agentId.charAt(0)<="Z"));
272 checknum2=((agentId.charAt(1)==1) || (agentId.charAt(1)==2));
273 if (checknum2 && checknum1){
274 id1 = agentId.charAt(0);
275 if (id1 == 'A') {id0=1;}
276 else if (id1 == 'B') { id0=10 ;}
277 else if (id1 == 'C') { id0=19 ;}
278 else if (id1 == 'D') { id0=28 ;}
279 else if (id1 == 'E') { id0=37 ;}
280 else if (id1 == 'F') { id0=46 ;}
281 else if (id1 == 'G') { id0=55 ;}
282 else if (id1 == 'H') { id0=64 ;}
283 else if (id1 == 'I') { id0=39 ;}
284 else if (id1 == 'J') { id0=73 ;}
285 else if (id1 == 'K') { id0=82 ;}
286 else if (id1 == 'L') { id0=2 ;}
287 else if (id1 == 'M') { id0=11 ;}
288 else if (id1 == 'N') { id0=20 ;}
289 else if (id1 == 'O') { id0=48 ;}
290 else if (id1 == 'P') { id0=29 ;}
291 else if (id1 == 'Q') { id0=38 ;}
292 else if (id1 == 'R') { id0=47 ;}
293 else if (id1 == 'S') { id0=56 ;}
294 else if (id1 == 'T') { id0=65 ;}
295 else if (id1 == 'U') { id0=74 ;}
296 else if (id1 == 'V') { id0=83 ;}
297 else if (id1 == 'W') { id0=21 ;}
298 else if (id1 == 'X') { id0=3 ;}
299 else if (id1 == 'Y') { id0=12 ;}
300 else if (id1 == 'Z') { id0=30 ;}
301 id2 = id0 + agentId.charAt(1)*8 + agentId.charAt(2)*7 + agentId.charAt(3)*6 + agentId.charAt(4)*5 + agentId.charAt(5)*4 + agentId.charAt(6)*3 + agentId.charAt(7)*2 + agentId.charAt(8)*1 + agentId.charAt(9)*1;
302 if (id2 % 10 == 0){
303 return true;
304 }
305 }
306 }
307 }
308 return false;
309}
310
311//轉換從UTF-8 到Big5 或 GB2312
312function Unicode2Str(str){
313var re=/&#[\da-fA-F]{1,5};/ig;
314var arr=str.match(re);
315if(arr==null)return("");
316var size=arr.length;
317var arr2=new Array(size);
318for(var i=0;i<arr.length;i++){
319arr2[i]=String.fromCharCode(arr[i].replace(/[&#;]/g,""));
320}
321for(var i=0;i<arr.length;i++){
322str=str.replace(arr[i],arr2[i]);
323}
324//return(arr.toString().replace(/,/g,""))
325return str;
326}
327
328//獲得當前客戶端時間 (Format: YYYYMMDD).
329function getCurrentDate(){
330var dateObj= new Date();
331var dateString=dateObj.getFullYear();
332if(dateObj.getMonth()<10){
333dateString=dateString+'0'+dateObj.getMonth();
334}else{
335dateString+=dateObj.getMonth();
336}
337if(dateObj.getDate()<10){
338dateString+='0'+dateObj.getDate();
339}else{
340dateString+=dateObj.getDate();
341}
342return dateString;
343}
344
345//居中顯示彈出窗口
346function PopWindowOnCenter(url,title,iwidth,iheight){
347var ileft,itop;
348ileft = (window.screen.width-iwidth)/2;
349itop = (window.screen.height-iheight)/2;
350
351window.open(url,title,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+iwidth+',height='+iheight+',left='+ileft+',top='+itop);
352}
353
354//移動選中的成員從objFromId的select到objToId的select
355function moveTo(objFromId,objToId){
356var objFrom = document.getElementById(objFromId);
357var objTo = document.getElementById(objToId);
358
359var len = objFrom.length;
360for(var i=len-1; i>=0; i--){
361if(objFrom.options[i].selected){
362var j = 0;
363for(j = 0; j < objTo.length; j++){
364if(objFrom.options[i].value == objTo.options[j].value){
365break;
366}
367}
368if(j == objTo.length){//the selected item is not in objTo.
369objFrom.options[i].selected = false;
370var option1 = objFrom.options[i];
371objTo.options.add(new Option(option1.text, option1.value));
372objFrom.options.remove(i);
373}
374objFrom = document.getElementById(objFromId);
375len = objFrom.length;
376}
377}
378}
379
380//移動全部成員從objFromId的select到objToId的select
381function moveAllTo(objFromId,objToId){
382var objFrom = document.getElementById(objFromId);
383var objTo = document.getElementById(objToId);
384
385var len = objFrom.length;
386for(var i=len-1; i>=0; i--){
387var j = 0;
388for(j = 0; j < objTo.length; j++){
389if(objFrom.options[i].value == objTo.options[j].value){
390break;
391}
392}
393if(j == objTo.length){//the selected item is not in objTo.
394var option1 = objFrom.options[i];
395objTo.options.add(new Option(option1.text, option1.value));
396objFrom.options.remove(i);
397}
398objFrom = document.getElementById(objFromId);
399len = objFrom.length;
400}
401}
402
403
404//屏蔽非數字鍵
405function checkKey(){
406if(event.keyCode<48 || (event.keyCode>57 && event.keyCode<96)
407|| event.keyCode>105){
408if(event.keyCode != 8){
409event.returnValue=false;
410}
411}
412}
413
414//用與樹狀列表的顯示
415function showMenu(id,ulId){
416var obj = document.getElementById(id);
417
418if(obj.className == ""){
419obj.className = "selected";
420document.getElementById(ulId).style.display = "block";
421}
422else{
423obj.className = "";
424document.getElementById(ulId).style.display = "none";
425}
426}
427
428//檢查str中是否包含漢字
429function CheckChinese( str){
430 var Strs = str;
431 var i;
432 for ( i=0;i<str.length;i++) {
433 if(str.charCodeAt(i)>=1000){
434 return true;
435 }
436 }
437 return false;
438}
439
440//校验是否全由数字组成
441
442程序代码
443function isDigit(s)
444{
445var patrn=/^[0-9]{1,20}$/;
446if (!patrn.exec(s)) return false
447return true
448}
449
450//校验登录名:只能输入5-20个以字母开头、可带数字、“_”、“.”的字串
451
452程序代码
453function isRegisterUserName(s)
454{
455var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
456if (!patrn.exec(s)) return false
457return true
458}
459
460//校验用户姓名:只能输入1-30个以字母开头的字串
461
462程序代码
463function isTrueName(s)
464{
465var patrn=/^[a-zA-Z]{1,30}$/;
466if (!patrn.exec(s)) return false
467return true
468}
469
470//校验密码:只能输入6-20个字母、数字、下划线
471
472程序代码
473function isPasswd(s)
474{
475var patrn=/^(w){6,20}$/;
476if (!patrn.exec(s)) return false
477return true
478}
479
480//校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”
481
482程序代码
483function isTel(s)
484{
485//var patrn=/^[+]{0,1}(d){1,3}[ ]?([-]?(d){1,12})+$/;
486var patrn=/^[+]{0,1}(d){1,3}[ ]?([-]?((d)|[ ]){1,12})+$/;
487if (!patrn.exec(s)) return false
488return true
489}
490
491//校验手机号码:必须以数字开头,除数字外,可含有“-”
492
493程序代码
494function isMobil(s)
495{
496var patrn=/^[+]{0,1}(d){1,3}[ ]?([-]?((d)|[ ]){1,12})+$/;
497if (!patrn.exec(s)) return false
498return true
499}
500
501//校验邮政编码
502
503程序代码
504function isPostalCode(s)
505{
506//var patrn=/^[a-zA-Z0-9]{3,12}$/;
507var patrn=/^[a-zA-Z0-9 ]{3,12}$/;
508if (!patrn.exec(s)) return false
509return true
510}
511
512//校验搜索关键字
513
514程序代码
515function isSearch(s)
516{
517var patrn=/^[^`~!@#$%^&*()+=|][]{}:;',.<>/?]{1}[^`~!@$%^&()+=|][]{}:;',.<>?]{0,19}$/;
518if (!patrn.exec(s)) return false
519return true
520}
521
522程序代码
523function isIP(s) //by zergling
524{
525var patrn=/^[0-9.]{1,20}$/;
526if (!patrn.exec(s)) return false
527return true
528}
529
530/**
531 * 功能:使指定值的指定名称的单复选框处于选中状态。
532 * radioName:单选框组件名
533 * val:指定值
534 */
535function makeRadioChecked(radioName, val) {
536 var obj = document.all[radioName];
537 try {
538 if (obj) {
539 if (obj.type == "radio" && obj.value == val) {
540 obj.checked = true;
541 }
542 for (var i = 0; i < obj.length; i++) {
543 if (obj[i].type == "radio" && obj[i].value == val) {
544 obj[i].checked = true;
545 break;
546 }
547 }
548 }
549 } catch(exception) {
550 alert("error");
551 }
552}
553
554自创javascrit分页代码。
555
556function showpages(total,perpage,current,filename,seed,bShow){
557//total总记录数,perpage每页记录数,current当前记录,filename文件名?page=,seed中间数字两边间隔数,bshow显示中间数字页面
558//
559
560
561var sRet,i,startPage,endPage,totalPage
562//startPage:循环开始/endPage:循环结束/totalPage:总页数
563//处理URL中的空格
564if (filename!=''){
565filename="&"+filename;
566}
567 if (total % perpage==0 ){
568
569 totalPage=total/perpage;
570
571}else{
572
573totalPage=Math.floor(total/perpage)+1;
574}
575
576
577 if (totalPage<=10){
578startPage=1;
579}else{
580if ((current-seed) >0) {
581startPage=current-seed;
582}else{
583startPage=1;
584}
585}
586
587if (totalPage<=10) {
588endPage=totalPage
589}else{
590if ((current+seed)<totalPage) {
591endPage=current+seed
592}else{
593endPage=totalPage
594}
595}
596
597if (current<seed) {
598if (totalPage>10){
599endPage=10
600}
601}
602 var sRet1=""
603
604 if (bShow) {
605for (i=startPage;i<=endPage;i++)
606{
607
608if (i==current)
609{
610sRet1=sRet1+"<font style=''><b>"+current+"</b></font> "
611}
612else
613{
614sRet1=sRet1+"<a href=?page="+i+filename+">"+i+"</a> "
615}
616
617}
618 }
619
620 sRet=""
621 //sRet=sRet+"<form name=jumpPage mothod=post action= >"
622sRet=sRet+"<font class=tcat2>共"+total+"条,"
623 sRet=sRet+"第"+current+"页/共"+ totalPage+"页, "
624sRet=sRet+"<a href=?page=1"+ filename+">第一页</a> "
625if ((current==1)&&(current!=totalPage)){
626
627
628sRet=sRet+" 上一页 "+sRet1+" <a href=?page="+(current+1) +filename+">下一页</a>"
629}else{
630if (current>1) {
631
632if (current<totalPage) {
633sRet=sRet+" <a href=?page="+(current-1)+filename+">上一页</a> "+sRet1+" <a href=?page="+(current+1)+filename+">下一页</a>"
634}else{
635if (current==totalPage) {
636sRet=sRet+" <a href=?page="+(current-1)+filename+">上一页</a> "+sRet1+" 下一页"
637
638}
639 }
640}else{
641sRet=sRet+" 上一页 "+sRet1+" 下一页"
642}
643}
644sRet=sRet+" <a href=?page="+ totalPage+filename+">最末页</a>"
645//sRet=sRet+"<input type=hidden name=wheretogo value=go> "
646//sRet=sRet+"<input type=hidden name=maxpage value="+totalPage+">"
647sRet=sRet+" 跳转到<input name=currentPage class=border1px size=3 onkeydown=if((event.keyCode==13)&&(this.value!='')&&(this.value!=0)&&(this.value<"+(totalPage+1)+"))window.location='?page='+this.value+'"+filename+"'; onkeyup=if(isNaN(this.value))this.value=''; >页 "
648//sRet=sRet+"<input type=button value=GO class=border1px onclick=jump('"+filename+"');> "
649
650sRet=sRet+"</font>"
651//sRet=sRet+"</form>"
652//alert(sRet);
653document.write(sRet)
654
655}
656
657检查有没有空格
658if(aa.indexOf(" ")>=0){
659 alert("aa中不允许含有空格!!");
660 document.myForm.aa.focus();
661 return false;
662}
663