JS代码判断集锦(之一)?
<script. language="JavaScript">?
function checkid(iden,year,month,day){?
if (iden.value.length==15) {?
if ((iden.value.lastIndexOf(month.value+day.value))==8) {?
return true;?
}?
return false;?
}?
if (iden.value.length==18) {?
if ((iden.value.indexOf(year.value+month.value+day.value))==6) {?
return true;?
}?
return false;?
}?
return false;?
}?
function isCharsInBag (s, bag)?
{?
var i;?
for (i = 0; i < s.length; i++)?
{?
var c = s.charAt(i);?
if (bag.indexOf(c) == -1) return false;?
}?
return true;?
}?
function isEmpty(s)?
{?
return ((s == null) || (s.length == 0))?
}?
function isWhitespace (s)?
{?
var whitespace = " \t\n\r";?
var i;?
for (i = 0; i < s.length; i++)?
{?
var c = s.charAt(i);?
if (whitespace.indexOf(c) >= 0)?
{?
return true;?
}?
}?
return false;?
}?
function isEmail (s,t)?
{?
if (isEmpty(s))?
{?
window.alert("输入的E-mail地址不能为空,请输入!");?
mobj = eval(t);?
mobj.focus();?
mobj.select();?
return false?
}?
if (isWhitespace(s))?
{?
window.alert("输入的E-mail地址中不能包含空格符,请重新输入!");?
mobj = eval(t)?
mobj.focus()?
mobj.select()?
return false;?
}?
var i = 1;?
var len = s.length;?
if (len > 50)?
{?
window.alert("email地址长度不能超过50位!");?
mobj = eval(t)?
mobj.focus()?
mobj.select()?
return false;?
}?
pos1 = s.indexOf("@");?
pos2 = s.indexOf(".");?
pos3 = s.lastIndexOf("@");?
pos4 = s.lastIndexOf(".");?
if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))?
{?
window.alert("请输入有效的E-mail地址!");?
mobj = eval(t)?
mobj.focus()?
mobj.select()?
return false;?