表单验证的javascript
function isEmail(theStr){
var atindex=theStr.indexOf('@');
var dotindex=theStr.indexOf('.',atindex);
var flag=true;
thesub=theStr.substring(0,dotindex+1);
if((atindex<1)||(atindex!=theStr.lastIndexOf('@'))||(dotindex<atindex+2)||(theStr.length<=thesub.length)){
flag=false;
}else{
flag=true;
}
return(flag);
}
function strDate(str){//1998-12-12
var reg = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
r[2]=r[2]-1;
var d= new Date(r[1], r[2],r[3]);
if(d.getFullYear()!=r[1])return false;
if(d.getMonth()!=r[2])return false;
if(d.getDate()!=r[3])return false;
return true;
}
function isPhone(theStr) {
var flag = true;
var trimStr = Trim(theStr);
var theindex = trimStr.indexOf('-',0);
var trimlen = trimStr.length;
var nextStr = trimStr;
if(theindex != -1) {
var firstStr = trimStr.substring(0, theindex);
nextStr = trimStr.substring(theindex+1, trimlen);
if((theindex != 3) && (theindex != 4))
flag = false;
var len = firstStr.length;
for(var j = 0; j < len; j++) {
if((nextStr.charAt(i) > '9') || (nextStr.charAt(i) < '0'))
flag = false;
}
if(nextStr.length == 0)
flag = false;
if(nextStr.indexOf('-',0) != -1)
flag = false;
}
else {
var nextLen = nextStr.length;
if(nextLen == 0)
flag = false;
if(nextStr.indexOf('-',0) != -1)
flag = false;
if((nextLen != 7) && (nextLen != 8))
flag = false;
for(var i = 0; i < nextLen; i++) {
if((trimStr.charAt(i)>'9') || (trimStr.charAt(i) <'0'))
flag = false;
}
}
return flag;
}
var pn = /^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$/;
if(!(pn.test(document.getElementById("JobDateTo").value)))
{
alert("日期格式不正确,请重新输入.");
document.getElementById("JobDateTo").focus();
return false;
}
var atindex=theStr.indexOf('@');
var dotindex=theStr.indexOf('.',atindex);
var flag=true;
thesub=theStr.substring(0,dotindex+1);
if((atindex<1)||(atindex!=theStr.lastIndexOf('@'))||(dotindex<atindex+2)||(theStr.length<=thesub.length)){
flag=false;
}else{
flag=true;
}
return(flag);
}
function strDate(str){//1998-12-12
var reg = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
r[2]=r[2]-1;
var d= new Date(r[1], r[2],r[3]);
if(d.getFullYear()!=r[1])return false;
if(d.getMonth()!=r[2])return false;
if(d.getDate()!=r[3])return false;
return true;
}
function isPhone(theStr) {
var flag = true;
var trimStr = Trim(theStr);
var theindex = trimStr.indexOf('-',0);
var trimlen = trimStr.length;
var nextStr = trimStr;
if(theindex != -1) {
var firstStr = trimStr.substring(0, theindex);
nextStr = trimStr.substring(theindex+1, trimlen);
if((theindex != 3) && (theindex != 4))
flag = false;
var len = firstStr.length;
for(var j = 0; j < len; j++) {
if((nextStr.charAt(i) > '9') || (nextStr.charAt(i) < '0'))
flag = false;
}
if(nextStr.length == 0)
flag = false;
if(nextStr.indexOf('-',0) != -1)
flag = false;
}
else {
var nextLen = nextStr.length;
if(nextLen == 0)
flag = false;
if(nextStr.indexOf('-',0) != -1)
flag = false;
if((nextLen != 7) && (nextLen != 8))
flag = false;
for(var i = 0; i < nextLen; i++) {
if((trimStr.charAt(i)>'9') || (trimStr.charAt(i) <'0'))
flag = false;
}
}
return flag;
}
var pn = /^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$/;
if(!(pn.test(document.getElementById("JobDateTo").value)))
{
alert("日期格式不正确,请重新输入.");
document.getElementById("JobDateTo").focus();
return false;
}
- 没有相关文章
- 没有评论