/**
* @date 2014/04/18
* @author wzj
* guestbook data check
*
**/
function checkForm()
{
var gosubmit = true;
//email check
var email = document.getElementById("email");
if(email.value != '')
{
if(!(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/).test(email.value))
{
alert('请输入有效的邮箱地址!');
email.focus();
gosubmit = false;
}
}
//telephone check
var tel = document.getElementById("tel");
if(!(/^1[3|4|5|8][0-9]\d{4,8}$/).test(tel.value))
{
alert('请输入有效的手机号!');
tel.focus();
gosubmit = false;
}
//qq check
var qq = document.getElementById("qq");
if(qq.value != '')
{
if(!(/^\d[1-9]{5,10}$/).test(qq.value))
{
alert('请输入有效的QQ号!');
qq.focus();
gosubmit = false;
}
}
return gosubmit;
}
<form action = "#" onsubmit = "return checkForm" method="post">
<input id = "email" type="text" />
<input id = "tel" type="text" />
<input id = "qq" type="text" />
</form>
原文链接:https://www.f2er.com/regex/361845.html