onsubmit="return check()"
function check(){
//验证姓名
var xingming= $("#xingming").val();
if(xingming == null || xingming == "")
{
document.getElementById('xingming').style.border="2px solid red";
return false;
} else {
document.getElementById('xingming').style.border="2px solid #3d3935";
}
//验证手机号码
var dianhua= $("#dianhua").val();
if(dianhua == null || dianhua == "")
{
document.getElementById('dianhua').style.border="2px solid red";
return false;
}
else{
var re = /^1\d{10}$/;
if(re.test(dianhua))
{
document.getElementById('dianhua').style.border="2px solid #3d3935";
}
else
{
document.getElementById('dianhua').style.border="2px solid red";
$('#dianhua').val("");
$('#dianhua').attr('placeholder', '请输入正确的手机号码!');
return false;
}
}
//验证邮箱
var youxiang= $("#youxiang").val();
if(youxiang == null || youxiang == "")
{
document.getElementById('youxiang').style.border="2px solid red";
return false;
}
else{
var re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
if(re.test(youxiang))
{
document.getElementById('youxiang').style.border="2px solid #3d3935";
}
else{
document.getElementById('youxiang').style.border="2px solid red";
$('#youxiang').val("");
$('#youxiang').attr('placeholder', '请输入正确的邮箱!');
return false;
}
}
return true;
}
网友评论