PbootCMS使用jquery驗證留言表單手機號碼和郵箱
為了避免表單數據被機器批量注入,因此需要對數據進行驗證是否符合標準。本次驗證主要是驗證手機號碼是否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();">
如果您的問題還未解決可以聯系站長付費協助。

有問題可以加入技術QQ群一起交流學習
本站vip會員 請加入無憂模板網 VIP群(50604020) PS:加入時備注用戶名或昵稱
普通注冊會員或訪客 請加入無憂模板網 技術交流群(50604130)
客服微信號:15898888535
聲明:本站所有文章資源內容,如無特殊說明或標注,均為采集網絡資源。如若內容侵犯了原著者的合法權益,可聯系站長刪除。