使用jquery驗證留言表單手機號碼和郵箱正則方式

2023-12-29    分類: 網(wǎng)站建設

為了避免表單數(shù)據(jù)被機器批量注入,因此需要對數(shù)據(jù)進行驗證是否符合標準。本次驗證主要是公司名稱必須為中文和驗證手機號碼是否11位,號碼號段格式是否正確,以及電子郵件是否按照標準格式來寫的。

<formaction="#"method="post"name="xihedemo"onsubmit="returnCheckForm();"><label>公司名稱</label><inputname="gongsi"type="text"><label>手機號碼</label><inputname="dianhua"type="text"><label>電子郵箱</label><inputname="youxiang"type="text"><inputtype="submit"value="提交信息"></form><scriptlanguage="javascript">functionCheckForm(){vargongsi=document.xihedemo.gongsi.value;if(gongsi.length==0){alert("請輸入公司名稱!");document.xihedemo.gongsi.focus();returnfalse;}if(!gongsi.match(/[(u4e00-u9fa5)(u3002|uff1f|uff01|uff0c|u3001|uff1b|uff1a|u201c|u201d|u2018|u2019|uff08|uff09|u300a|u300b|u3010|u3011|u007e)]+/)){alert("請輸入正確的公司名稱,公司名稱必須是中文及中文符號!");document.xihedemo.gongsi.focus();returnfalse;}vardianhua=document.xihedemo.dianhua.value;if(dianhua.length==0){alert("請輸入手機號碼!");document.xihedemo.dianhua.focus();returnfalse;}if(dianhua.length!==11){alert("請輸入11位手機號碼!");document.xihedemo.dianhua.focus();returnfalse;}if(!dianhua.match(/^(?:(?:+|00)86)?1(?:(?:3[d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[d])|(?:9[189]))d{8}$/)){alert("請輸入有效的手機號碼!");document.xihedemo.dianhua.focus();returnfalse;}varyouxiang=document.xihedemo.youxiang.value;if(youxiang.length==0){alert("請輸入電子郵箱!");document.xihedemo.youxiang.focus();returnfalse;}if(!youxiang.match(/^[A-Za-z0-9u4e00-u9fa5]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$/)){alert("請輸入正確的電子郵箱!");document.xihedemo.youxiang.focus();returnfalse;}returntrue;}</script>

網(wǎng)站欄目:使用jquery驗證留言表單手機號碼和郵箱正則方式
標題來源:http://www.bm7419.com/news10/311010.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、App設計、網(wǎng)站導航網(wǎng)站設計公司、網(wǎng)站改版云服務器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設