验证年龄
function checkage(value)
{
var ch=\"/[0-9](2)/\"; 1。创建验证年龄的正则式
if(value==' ') 2.匹配value值
{
alert(\"age为空!\"); 3.输入为空报错
return false;
}
if(!ch.exec(value))
{
alert(\"年龄不合法!\"); 4.输入不符合正则式报错
return false;
}
return true; 5.年龄合法
}
验证ID
function checkID(value)
{
var ch=\"/[0-9](8)/\"; 1。创建验证ID的正则式
if(value=='')
{
alert(\"ID为空!\"); 2.输入为空
return false;
}
if(!ch.exec(value))
{
alert(\"用户名不合法!\"); 3.输入不符和用户ID
return false; 4.ID合法
}
return true;
}
验证日期
function checkDays()
{
var ch=\"/[1-9]?/\";
1.获得年 月 日
var Year=document.all(\"year\");
var Year=document.all(\"month\");
var Year=document.all(\"day\");
2. 验证输入是否为数字
if(Year==' '||Month==' '||Day)
{
alert(\"输入为空!\");
}
if(!ch.exec(Year))
{
return false;
}
if(!ch.exec(month))
{
return false;
}
if(!ch.exec(day))
{
return false;
}
3.验证月的范围
if(month>12||month<0)
{
alert(\"月错误!\");
return false;
}
4.验证平年和闰年的二月
if(Year%4==0&&day!=28)
{
alert(\"二月应为28天\");
return false;
}
if(Year%4!=0&&day!=29)
{
alert(\"二月应为29天\");
return false;
}
5.验证31该月是否为31天
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
if(day!=31)
{
alert(\"该月因为31天!\");
return false;
}
}
6.验证31该月是否为30天
if(month==4||month==6||month==9||month==30)
{
if(day!=30)
{
alert(\"该月因为30天!\");
return false;
}
}
7.日期合法
return true;
}
验证e-mail
function checkemail(value)
{
var
ch=\"^(\\w+((-\\w+)|(\\.\\w+))*)\\+\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$\"; 1.创建验证邮箱地址的正则式
if(value=='')
{
alert(\"邮箱为空!\"); 2.输入为空错误
return false;
}
if(!ch.exec(value))
{
alert(\"邮箱地址不合法!\"); 4.邮箱不合法
return false;
}
return true; 5。邮箱格式合法
}
验证电话
function checkTel(value)
{
var
|([1][2]\\d{1}|[0]\\d{3}-)?(\\d{7}|\\d{8})\";
ch=\"(\\d{11})|(\\d{3}|(\\d{3}|\\d{4})-)?(\\d{8}|\\d{7})
1.创建验证电话的正则式
if(value==' ' )
{
alert(\"输入为空!\") 2.输入为空
return false;
}
if(!ch.exec(value))
{
alert(\"电话格式不合法\"); 3.输入不合法
return false;
}
return true; 4。电话号码合法
}
验证其他输入框通用函数
function checkNull(value,id)
{
var name=document.all(\"id\").name; 1.获得输入框名称
if(value=='')
{
alert(name+\"输入为空\"); 2.输入为空报错
return false;
}
return true; 3.输入合法
}