PbootCMS使用jquery验证留言表单手机号码和邮箱
PbootCMS留言板验证手机号和邮箱是否正确
为了避免表单数据被机器批量注入,因此需要对数据进行验证是否符合标准。本次验证主要是验证手机号码是否11位,号码号段格式是否正确,以及电子邮件是否按照格式来写的。
1.将如下代码放在有留言的模版的head里面。
<script language="javascript">
function CheckForm()
{
var tel = document.zhimatong.tel.value;
if (tel.length == 0) {
alert("请输入手机号码!");
document.zhimatong.tel.focus();
return false;
}
if (tel.length !== 11) {
alert("请输入有效的手机号码!");
document.zhimatong.tel.focus();
return false;
}
if(!tel.match(/^1[3|4|5|8][0-9]\d{4,8}$/)){
alert("请输入有效的手机号码!");
document.zhimatong.tel.focus();
return false;
}
var email = document.zhimatong.mail.value;
if (email.length == 0) {
alert("请输入电子邮箱!");
document.zhimatong.mail.focus();
return false;
}
if(!email.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)){
alert("请输入正确的电子邮箱!");
document.zhimatong.mail.focus();
return false;
}
return true;
}
</script>2.修改form
<form action="{pboot:msgaction}" method="post" name="zhimatong" onsubmit="return CheckForm();"> 本文属原创,转载请注明原文:https://www.zhimatong.com/jiaocheng/776.html
为保证教程的实用性及扩大知识面覆盖,如果您有相似问题而未解决,可联系在线客服免费技术支持。
点赞 1



交流群
购物车