国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 後端開發(fā) php教程 Ajax和PHP正規(guī)表示式驗(yàn)證表單及驗(yàn)證碼

Ajax和PHP正規(guī)表示式驗(yàn)證表單及驗(yàn)證碼

Feb 03, 2017 pm 05:48 PM

模式匹配:

:轉(zhuǎn)義字元例如:b轉(zhuǎn)義了b?

^:正規(guī)表示式開始符號(hào)?

$:正規(guī)表示式結(jié)束符號(hào)?


$:正規(guī)表示式結(jié)束符號(hào)?

或n次?


+:符合前面的字元出現(xiàn)1次或n次?


?:符合前面的字元出現(xiàn)0次或1次?


.:符合除了換行符以外的所有單一字元?


|:或的意思,例如x|y 匹配x或y?


{n}:匹配前面的n個(gè)字符?


{n,m}:匹配至少n個(gè)最多m個(gè)前面字符?


[xyz ]:符合中括號(hào)裡的任一個(gè)字元?


[^xyz]:符合除了中括號(hào)裡的任一個(gè)字元等價(jià)於[0-9]?


w:符合任一個(gè)數(shù)字或字母或底線等價(jià)於[A-Za-z0-9_]?


d:符合任一0--9之間的數(shù)字?


模式修正子:?


i:忽略大小寫例相說明


//使用者名稱由6-18位的字母數(shù)字底線組成,不能由數(shù)字開頭?


var r_name=/^[a-z]w{5,17}$/i?


//密碼長度不能少於六位?


var r_pwd=/^w{6,}$/?


//所有的通用郵箱地址?


var r_eamil=/^w+@w+(.)w+配對(duì)一個(gè)QQ信箱位址?


//861745122@qq.com?

var r_qq_email=/^d{5,}@qq(.)com$/?


郵件
//符合一個(gè)163的郵件信箱

=/^w+@163(.)com$/?


//符合一個(gè)後綴名可能是.com|.net|.cn|.edu?


var email=/^w+@w+(.)com| net|cn|edu$/?


//要求輸入有效的年齡層?


var r_age=/^d{1,2}$/?


//if(age>=18&age=188&age=18)


//驗(yàn)證手機(jī)號(hào)碼:11位13 15 18開頭?


var r_tel=/^1[3,5,8]d{9}$/?


//驗(yàn)證身分證編號(hào)18位元或17位加一X?


var r_s=/^d{18}|d{17}x$/i?


//驗(yàn)證中文var reg=/^[u4e00-u9fa5]{2,17}$/?

//php?


$reg = "/^[x{4e00}-x{9fa5}]$/u"?

<span style="font-size:24px;">下面是一個(gè)例子:</span> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 
<title></title> 
<script type="text/javascript" src="public.js"></script> 
</head> 
<body onload="yanzheng(this)"> 
<form method="post" action="info_2.php" onsubmit="return check_all()"> 
<table> 
<tr> 
<td colspan="2">賬戶基本信息</td> 
</tr> 
<tr> 
<td>登錄賬號(hào):</td> 
<td><input type="text" name="zhanghao" onblur="check_zhanghao(this)"><span name="sp1"></span></td> 
</tr> 
<tr> 
<td>昵稱:</td> 
<td><input type="text" name="nicheng" onblur="check_nicheng(this)"><span name="sp2"></span></td> 
</tr> 
<tr> 
<td>性別:</td> 
<td><input type="radio" name="sex" value="男"onclick="check_sex()">男 
<input type="radio" name="sex" value="女"onclick="check_sex()">女 
<span id="sp3"></span></td> 
</tr> 
<tr> 
<td colspan="2">賬戶安全設(shè)置</td> 
</tr> 
<tr> 
<td>登錄密碼:</td> 
<td><input type="password" name="pwd" onblur="check_pwd(this)"><span name="sp4"></span></td> 
</tr> 
<tr> 
<td>確認(rèn)登錄密碼:</td> 
<td><input type="password" name="repwd" onblur="check_repwd(this)"><span name="sp5"></span></td> 
</tr> 
<tr> 
<td>真實(shí)姓名:</td> 
<td><input type="text" name="username" onblur="check_username(this)"><span name="sp6"></span></td> 
</tr> 
<tr> 
<td>身份證號(hào):</td> 
<td><input type="text" name="idcard" onblur="check_idcard(this)"><span name="sp7"></span></td> 
</tr> 
<tr> 
<td>郵箱地址:</td> 
<td><input type="text" name="email" onblur="check_email(this)"><span name="sp8"></span></td> 
</tr> 
<tr> 
<td>驗(yàn)證碼</td> 
<td><input type="text" id="number" onblur="check_number()"> 
<input type="button" onclick="yanzheng()" value="獲取驗(yàn)證碼" > 
<span id="sp10"></span> 
<span id="sp9"></span> 
</td> 
</tr> 
<tr> 
<td></td> 
<td><input type="submit" value="免費(fèi)注冊(cè)"></td> 
</tr> 
</table> 
</form> 
<script type="text/javascript"> 
//驗(yàn)證登錄賬號(hào) 
function check_zhanghao(obj){ 
var sp1=$(&#39;sp1&#39;); 
if(obj.value==&#39;&#39;){ 
sp1.innerHTML=&#39;登錄賬號(hào)不能為空&#39;; 
sp1.style.color=&#39;red&#39;; 
return false; 
}else{ 
var reg=/^\w{5,10}$/i; 
if(reg.test(obj.value)){ 
sp1.innerHTML=&#39;正確&#39;; 
sp1.style.color=&#39;green&#39;; 
return true; 
}else{ 
sp1.innerHTML=&#39;登錄賬號(hào)5-10字符&#39;; 
sp1.style.color=&#39;red&#39;; 
return false; 
} 
}return true; 
} 
//驗(yàn)證昵稱 
function check_nicheng(obj){ 
var sp2=$(&#39;sp2&#39;); 
if(obj.value==&#39;&#39;){ 
sp2.innerHTML=&#39;登錄賬號(hào)不能為空&#39;; 
sp2.style.color=&#39;red&#39;; 
return false; 
}else{ 
var reg=/^\w{5,10}$/i; 
if(reg.test(obj.value)){ 
sp2.innerHTML=&#39;正確&#39;; 
sp2.style.color=&#39;green&#39;; 
return true; 
}else{ 
sp2.innerHTML=&#39;昵稱5-10字符&#39;; 
sp2.style.color=&#39;red&#39;; 
return false; 
} 
}return true; 
} 
//驗(yàn)證密碼 
function check_pwd(obj2){ 
var sp4=$(&#39;sp4&#39;); 
if(obj2.value==&#39;&#39;){ 
sp4.innerHTML=&#39;密碼不能為空&#39;; 
sp4.style.color=&#39;red&#39;; 
return false; 
}else{ 
var reg=/^\w{6,}$/; 
if(reg.test(obj2.value)){ 
sp4.innerHTML=&#39;正確&#39;; 
sp4.style.color=&#39;green&#39;; 
return true; 
}else{ 
sp4.innerHTML=&#39;格式不正確&#39;; 
sp4.style.color=&#39;red&#39;; 
return false; 
} 
}return true; 
} 
//驗(yàn)證確認(rèn)密碼 
function check_repwd(obj3){ 
var sp5=$(&#39;sp5&#39;); 
var pwd=$(&#39;pwd&#39;); 
var repwd=$(&#39;repwd&#39;); 
if(obj3.value==&#39;&#39;){ 
sp5.innerHTML=&#39;密碼不能為空&#39;; 
sp5.style.color=&#39;red&#39;; 
return false; 
}else{ 
if(obj3.value==pwd.value){ 
sp5.innerHTML=&#39;正確&#39;; 
sp5.style.color=&#39;green&#39;; 
return true; 
}else{ 
sp5.innerHTML=&#39;確認(rèn)密碼和密碼不一致&#39;; 
sp5.style.color=&#39;red&#39;; 
return false; 
} 
}return true; 
} 
//驗(yàn)證性別 
num2=0; 
function check_sex(){ 
var sex=document.getElementsByName(&#39;sex&#39;); 
// var sp4=document.getElementById(&#39;sp4&#39;) 
for(var i=0;i<sex.length;i++){ 
if(sex[i].checked==true){ 
num2=num2+1; 
} 
} 
//alert(num2); 
if(num2!=0){ 
sp3.innerHTML=&#39;√&#39;; 
sp3.style.color=&#39;green&#39;; 
return true; 
}else{ 
sp3.innerHTML=&#39;性別不能為空&#39;; 
sp3.style.color=&#39;red&#39;; 
return false; 
} 
} 
//驗(yàn)證姓名 
function check_username(obj){ 
var sp6=$(&#39;sp6&#39;); 
if(obj.value==""){ 
sp6.innerHTML=&#39;用戶名不能為空&#39;; 
sp6.style.color=&#39;red&#39;; 
return false; 
}else{ 
var reg=/^[\u4e00-\u9fa5]{2,3}$/; 
if(!reg.test(obj.value)){ 
sp6.innerHTML=&#39;用戶名應(yīng)該2-3個(gè)漢字&#39;; 
sp6.style.color=&#39;red&#39;; 
return false; 
}else{ 
sp6.innerHTML=&#39;√&#39;; 
sp6.style.color=&#39;green&#39;; 
return true; 
} 
} 
return true; 
} 
//驗(yàn)證郵箱 
function check_email(obj5){ 
var sp8=$(&#39;sp8&#39;); 
if(obj5.value==&#39;&#39;){ 
sp8.innerHTML=&#39;郵箱不能為空&#39;; 
sp8.style.color=&#39;red&#39;; 
return false; 
}else{ 
var reg=/^(\w+@\w+(\.)com|net|cn)$/; 
if(reg.test(obj5.value)){ 
sp8.innerHTML=&#39;正確&#39;; 
sp8.style.color=&#39;green&#39;; 
return true; 
}else{ 
sp8.innerHTML=&#39;格式不正確&#39;; 
sp8.style.color=&#39;red&#39;; 
return false; 
}return true; 
} 
} 
//驗(yàn)證身份證號(hào) 
function check_idcard(obj9){ 
var sp7=$(&#39;sp7&#39;); 
if(obj9.value==&#39;&#39;){ 
sp7.innerHTML=&#39;身份證號(hào)不能為空&#39;; 
sp7.style.color=&#39;red&#39;; 
return false; 
}else{ 
var reg=/^\d{18}|\d{17}x$/i; 
if(reg.test(obj9.value)){ 
sp7.innerHTML=&#39;正確&#39;; 
sp7.style.color=&#39;green&#39;; 
return true; 
}else{ 
sp7.innerHTML=&#39;格式不正確&#39;; 
sp7.style.color=&#39;red&#39;; 
return false; 
}return true; 
} 
} 
//生成驗(yàn)證碼 
function yanzheng(){ 
var sp9=document.getElementById(&#39;sp9&#39;); 
var str1=""; 
for(var i=1;i<=4;i++){ 
str1=str1+parseInt(Math.random()*10); 
sp9.innerHTML=str1; 
} 
} 
//驗(yàn)證驗(yàn)證碼 
function check_number(){ 
var number=document.getElementById(&#39;number&#39;).value 
var sp10=document.getElementById(&#39;sp10&#39;) 
var sp9=document.getElementById(&#39;sp9&#39;); 
if(number==""){ 
sp10.innerHTML=&#39;驗(yàn)證碼不能為空&#39;; 
sp10.style.color=&#39;red&#39;; 
return false; 
}else{ 
if(number!=sp9.innerHTML){ 
sp10.innerHTML=&#39;驗(yàn)證碼和你寫的不一致&#39;; 
sp10.style.color=&#39;red&#39;; 
return false; 
} else{ 
sp10.innerHTML=&#39;√&#39;; 
sp10.style.color=&#39;green&#39;; 
return true;} 
return true; 
} 
} 
function check_all(){ 
if(check_zhanghao($(&#39;zhanghao&#39;)) & check_nicheng($(&#39;nicheng&#39;)) & check_pwd($(&#39;pwd&#39;)) & check_repwd($(&#39;repwd&#39;)) & check_sex()& check_username($(&#39;username&#39;)) & check_idcard($(&#39;idcard&#39;)) &check_email($(&#39;email&#39;)) & check_number() ){ 
return true;} 
else{ return false;} 
} 
</script> 
</body> 
</html>

php正規(guī)驗(yàn)證

<?php 
header("content-type:text/html;charset=utf8"); 
//var_dump($_POST);die; 
//array(5) { ["uname"]=> string(9) "劉偉超" ["uqq"]=> string(10) "1111111111" ["uemail"]=> string(12) "66555@qq.com" ["utel"]=> string(11) "15863162320" ["uinfo"]=> string(48) "地方開始放假開放活動(dòng)健康的話概括" } 
empty($_POST["uname"])?$uname="":$uname=$_POST["uname"]; 
empty($_POST["uemail"])?$uemail="":$uemail=$_POST["uemail"]; 
empty($_POST["utel"])?$utel="":$utel=$_POST["utel"]; 
empty($_POST["uqq"])?$uqq="":$uqq=$_POST["uqq"]; 
empty($_POST["uinfo"])?$uinfo="":$uinfo=$_POST["uinfo"]; 
//驗(yàn)證姓名 
$reg="/^[\x{4e00}-\x{9fa5}]{2,3}$/u"; 
if(!preg_match($reg,$uname)){ 
echo "用戶名應(yīng)該2-3個(gè)漢字";die; 
//header("refresh:1;url=form.html"); 
} 
//驗(yàn)證郵箱 
$reg="/^(\w+@\w+(\.)com|net|cn)$/"; 
if(!preg_match($reg,$uemail)){ 
echo "郵箱必須含有@,且以com結(jié)尾";header("refresh:1;url=form.html"); die; 
} 
//驗(yàn)證座機(jī)號(hào) 
$reg="/^\d{11}$/"; 
if(!preg_match($reg,$utel)){ 
echo "座機(jī)號(hào)以010-22222222格式";header("refresh:1;url=form.html"); die; 
} 
//驗(yàn)證QQ號(hào) 
$reg="/^\d{5,11}$/"; 
if(!preg_match($reg,$uqq)){ 
echo "qq必須是5-11位純數(shù)字";header("refresh:1;url=form.html"); die; 
} 
//驗(yàn)證簡介 
/*$reg="/^[\x{4e00}-\x{9fa5}]{10,100}\W+/u"; 
if(!preg_match($reg,$uinfo)){ 
echo "簡介應(yīng)該10-100個(gè)漢字";die; 
//header("refresh:1;url=form.html"); 
} 
*/
//連接數(shù)據(jù)庫 
$link=mysql_connect(&#39;127.0.0.1&#39;,&#39;root&#39;,&#39;root&#39;)or die("連接失敗"); 
//選擇數(shù)據(jù)庫 
mysql_select_db(&#39;kaoshi&#39;,$link); 
//設(shè)置字符集 
mysql_query("set names utf8"); 
//寫sql語句 
$sql="insert into zhuce(c_name,c_qq,c_email,c_tel,c_info) values(&#39;$uname&#39;,&#39;$uqq&#39;,&#39;$uemail&#39;,&#39;$utel&#39;,&#39;$uinfo&#39;)"; 
//echo $sql;die; 
$rel=mysql_query($sql); 
if($rel){ 
echo "注冊(cè)成功";header("refresh:1;url=show.php"); 
}else{echo "注冊(cè)失敗";header("refresh:1;url=form.html");} 
?>

以上所述是小編給大家介紹的Ajax和PHP正規(guī)表示式驗(yàn)證表單及驗(yàn)證碼,希望對(duì)大家有幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回覆大家的。在此也非常感謝大家對(duì)PHP中文網(wǎng)的支持!

更多Ajax和PHP正規(guī)表示式驗(yàn)證表單及驗(yàn)證碼相關(guān)文章請(qǐng)關(guān)注PHP中文網(wǎng)!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)程式碼編輯軟體(SublimeText3)

對(duì)基於PHP的API進(jìn)行版本控制的最佳實(shí)踐是什麼? 對(duì)基於PHP的API進(jìn)行版本控制的最佳實(shí)踐是什麼? Jun 14, 2025 am 12:27 AM

基於toversionaphp,useUrl deuseUrl specteringforclarityAndEsofRouting,單獨(dú)的codetoavoidConflicts,dremecateOldVersionswithClearCommunication,andConsiderCustomHeadeSerlySerallyWhennEnncelsy.startbyplacingtheversionIntheUrl(E.G.,epi/api/v

如何在PHP中實(shí)施身份驗(yàn)證和授權(quán)? 如何在PHP中實(shí)施身份驗(yàn)證和授權(quán)? Jun 20, 2025 am 01:03 AM

tosecurelyhandleauthenticationandationallizationInphp,lofterTheSesteps:1.AlwaysHashPasswordSwithPassword_hash()andverifyusingspasspassword_verify(),usepreparedStatatementStopreventsqlineptions,andStoreSeruserDatain usseruserDatain $ _sessiveferterlogin.2.implementrole-2.imaccessccsccccccccccccccccccccccccc.

PHP中的程序和麵向?qū)ο蟮木幊坦?fàn)例之間有什麼區(qū)別? PHP中的程序和麵向?qū)ο蟮木幊坦?fàn)例之間有什麼區(qū)別? Jun 14, 2025 am 12:25 AM

procemal and object-tiriendedprogromming(oop)inphpdiffersimplessintustructure,可重複使用性和datahandling.1.procedural-Progrogursmingusesfunctimesfunctionsormanized sequalized sequalized sequiential,poiperforsmallscripts.2.OpporganizesCodeOrganizescodeOdeIntsocloceSandObjects,ModelingReal-Worlden-Worlden

PHP中有哪些弱參考(弱圖),何時(shí)有用? PHP中有哪些弱參考(弱圖),何時(shí)有用? Jun 14, 2025 am 12:25 AM

PHPdoesnothaveabuilt-inWeakMapbutoffersWeakReferenceforsimilarfunctionality.1.WeakReferenceallowsholdingreferenceswithoutpreventinggarbagecollection.2.Itisusefulforcaching,eventlisteners,andmetadatawithoutaffectingobjectlifecycles.3.YoucansimulateaWe

如何在PHP中安全地處理文件上傳? 如何在PHP中安全地處理文件上傳? Jun 19, 2025 am 01:05 AM

要安全處理PHP中的文件上傳,核心在於驗(yàn)證文件類型、重命名文件並限制權(quán)限。 1.使用finfo_file()檢查真實(shí)MIME類型,僅允許特定類型如image/jpeg;2.用uniqid()生成隨機(jī)文件名,存儲(chǔ)至非Web根目錄;3.通過php.ini和HTML表單限製文件大小,設(shè)置目錄權(quán)限為0755;4.使用ClamAV掃描惡意軟件,增強(qiáng)安全性。這些步驟有效防止安全漏洞,確保文件上傳過程安全可靠。

如何與PHP的NOSQL數(shù)據(jù)庫(例如MongoDB,Redis)進(jìn)行交互? 如何與PHP的NOSQL數(shù)據(jù)庫(例如MongoDB,Redis)進(jìn)行交互? Jun 19, 2025 am 01:07 AM

是的,PHP可以通過特定擴(kuò)展或庫與MongoDB和Redis等NoSQL數(shù)據(jù)庫交互。首先,使用MongoDBPHP驅(qū)動(dòng)(通過PECL或Composer安裝)創(chuàng)建客戶端實(shí)例並操作數(shù)據(jù)庫及集合,支持插入、查詢、聚合等操作;其次,使用Predis庫或phpredis擴(kuò)展連接Redis,執(zhí)行鍵值設(shè)置與獲取,推薦phpredis用於高性能場(chǎng)景,Predis則便於快速部署;兩者均適用於生產(chǎn)環(huán)境且文檔完善。

PHP中==(鬆散比較)和===(嚴(yán)格的比較)之間有什麼區(qū)別? PHP中==(鬆散比較)和===(嚴(yán)格的比較)之間有什麼區(qū)別? Jun 19, 2025 am 01:07 AM

在PHP中,==與===的主要區(qū)別在於類型檢查的嚴(yán)格程度。 ==在比較前會(huì)進(jìn)行類型轉(zhuǎn)換,例如5=="5"返回true,而===要求值和類型都相同才會(huì)返回true,例如5==="5"返回false。使用場(chǎng)景上,===更安全應(yīng)優(yōu)先使用,==僅在需要類型轉(zhuǎn)換時(shí)使用。

如何在PHP( - , *, /,%)中執(zhí)行算術(shù)操作? 如何在PHP( - , *, /,%)中執(zhí)行算術(shù)操作? Jun 19, 2025 pm 05:13 PM

PHP中使用基本數(shù)學(xué)運(yùn)算的方法如下:1.加法用 號(hào),支持整數(shù)和浮點(diǎn)數(shù),也可用於變量,字符串?dāng)?shù)字會(huì)自動(dòng)轉(zhuǎn)換但不推薦依賴;2.減法用-號(hào),變量同理,類型轉(zhuǎn)換同樣適用;3.乘法用*號(hào),適用於數(shù)字及類似字符串;4.除法用/號(hào),需避免除以零,並註意結(jié)果可能是浮點(diǎn)數(shù);5.取模用%號(hào),可用於判斷奇偶數(shù),處理負(fù)數(shù)時(shí)餘數(shù)符號(hào)與被除數(shù)一致。正確使用這些運(yùn)算符的關(guān)鍵在於確保數(shù)據(jù)類型清晰並處理好邊界情況。

See all articles