99.{
100.if (allowstrlist.indexOf(obj.value.substr(i,1))!
=-1)
101.{
102.endvalue=false;
103.break;
104.}
105.}
106.if(endvalue==false)
107.{
108.if (show) alert(ShowMsg);
109.obj.focus();
110.obj.select();
111.return false;
112.}
113.//邮件地址正确
114.return true;
115.}
116.else
117.{
118.//请输入电子信箱地址
119.if (show) alert(ShowMsg);
120.obj.focus();
121.obj.select();
122.return false;
123.}
124.}
125.
126./*
127.==================================================================
128.功能:
检查输入的是否为数字
129.提示信息:
未输入或输入的不是一个合法的数字!
130.使用:
isNumeric(obj,string)
131.返回:
bool
132.==================================================================
133.*/
134.function isNumeric(obj,ShowMsg)
135.{
136.var show = IfShow(ShowMsg) ;
137.
138.var IfTrue = obj.value.search(/^(-|\+)?
\d+(\.\d+)?
$/) !
= -1;
139.
140.if (show && IfTrue ==false)
141.{
142.alert(ShowMsg);
143.obj.focus();
144.obj.select();
145.return false;
146.}
147.else
148.{
149.return true;
150.}
151.}
152.
153./*
154.==================================================================
155.功能:
打印
156.使用:
Print()
157.返回:
158.==================================================================
159.*/
160.function Print()
161.{
162.
163.document.all.print.style.display = "none";
164.window.print();
165.window.close();
166.}
167.
168./*
169.==================================================================
170.功能:
判断是否为日期(格式:
yyyy-mm-dd)
171.提示信息:
未输入或输入的日期格式错误!
172.使用:
isDate(obj,string)
173.返回:
bool
174.==================================================================
175.*/
176.function isDate(obj,ShowMsg)
177.{
178.var show = IfShow(ShowMsg) ;
179.
180.if(obj.value==null)
181.{
182.if (show) alert(ShowMsg);
183.return false;
184.}
185.
186.if(obj.value=="")
187.{
188.if (show) alert(ShowMsg);
189.return false;
190.}
191.
192.var datePat=/^(\d{2}|\d{4})(\-)(\d{1,2})(\-)(\d{1,2})$/;
193.
194.var dateStr=obj.value;
195.// is the format ok?
196.var matchArray = dateStr.match(datePat);
197.
198.
199.if (matchArray==null)
200.{
201.if (show) alert(ShowMsg);
202.return false;
203.}
204.year=matchArray[1];
205.month=matchArray[3];
206.day=matchArray[5];
207.
208.if (year.length!
=4 || month.length!
=2 || day.length!
=2)
209.{
210.if (show) alert(ShowMsg);
211.return false;
212.}
213.if (month < 1 || month > 12)
214.{
215.if (show) alert(ShowMsg);
216.return false;
217.}
218.if (day < 1 || day > 31)
219.{
220.if (show) alert(ShowMsg);
221.return false;
222.}
223.
224.if ((month==4 || month==6 || month==9 || month==11) && day==31)
225.{
226.if (show) alert(ShowMsg);
227.return false;
228.}
229.
230.if (month==2)
231.{
232.var isleap=(year % 4==0 && (year % 100 !
=0 || year % 400==0));
233.if (day>29 || ((day==29) && (!
isleap)))
234.{
235.if (show) alert(ShowMsg);
236.return false;
237.}
238.}
239.return true;
240.}
241.
242./*
243.==================================================================
244.功能:
日期大小判断(格式:
yyyy-mm-dd)
245.提示信息:
未输入或输入的开始日期大于结束日期!
246.使用:
JudgeDate(obj1,obj2,string)
247.返回:
bool
248.==================================================================
249.*/
250.function JudgeDate(obj1,obj2,ShowMsg)
251.{
252.var show = IfShow(ShowMsg) ;
253.
254.var eva = isDate(obj1,"") && isDate(obj2,"");
255.
256.if(obj1.value!
="" && obj2.value!
="" & eva !
= false)
257.{
258.var date1 = obj1.value;
259.var myDate1 = Date.parse(date1.replace("-","/"));
260.var date2 = obj2.value;
261.var myDate2 = Date.parse(date2.replace("-","/"));
262.if(myDate1 > myDate2)
263.{
264.if (show) alert(ShowMsg);
265.return false;
266.}
267.else
268.{
269.return true;
270.}
271.}
272.else
273.{
274.if (show) alert(ShowMsg);
275.return false;
276.}
277.}
278.
279./*
280.==================================================================
281.功能:
字符串操作,去除字符串两边的空格
282.使用:
Trim(string)
283.返回:
string
284.==================================================================
285.*/
286./*
287.==================================================================
288.功能:
去除左边的空格
289.使用:
LTrim(string)
290.返回:
string
291.==================================================================
292.*/
293.function LTrim(str)
294.{
295.var whitespace = new String(" \t\n\r");
296.var s = new String(str);
297.
298.if (whitespace.indexOf(s.charAt(0)) !
= -1)
299.{
300.var j=0, i = s.length;
301.while (j < i && whitespace.indexOf(s.charAt(j)) !
= -1)
302.{
303.j++;
304.}
305.s = s.substring(j, i);
306.}
307.return s;
308.}
309.
310./*
311.==================================================================
312.功能:
去除右边的空格
313.使用:
RTrim(string)
314.返回:
string
315.==================================================================
316.*/
317.function RTrim(str)
318.{
319.var whitespace = new String(" \t\n\r");
320.var s = new String(str);
321.
322.if (whitespace.indexOf(s.charAt(s.length-1)) !
= -1)
323.{
324.var i = s.length - 1;
325.while (i >= 0 && whitespace.indexOf(s.charAt(i)) !
= -1)
326.{
327.i--;
328.}
329.s = s.substring(0, i+1);
330.}
331.return s;
332.}
333.
334.//去除前后空格
335.function Trim(str)
336.{
337.return RTrim(LTrim(str));
338.}
339.
340.
341./*
342.==================================================================
343.功能:
无效字符的检测(不允许输入特殊字符)
344.提示信息:
未输入或输入包含非法字符
345.使用:
CheckChar(obj,Lchar,string)
346.Lchar:
要检查的特殊字符
347.返回:
bool
348.==================================================================
349.*/
350.function CheckChar(obj,Lchar,ShowMsg)
351.{
352.var show = IfShow(ShowMsg);
353.
354.var strlist = Lchar; //"~!
@#$%^&*?
<>\"\'";
355.
356.//无效字符的检测
357.if(obj.value!
= "")
358.{
359.var tmpbool=true;
360.for (i=0;i361.{
362.if(strlist.indexOf(obj.value.substr(i,1))!
=-1)
363.{
364.tmpbool=false;
365.break;
366.}
367.else
368.{}
369.}
370.
371.if(tmpbool==false)
372.{
373.if (show) alert(ShowMsg + strlist);
374.obj.focus();
375.obj.select();
376.return false;
377.}
378.else
379.{
380.return true;
381.}
382.}
383.else
38