標籤:bsp button 1.0 set w3c ted 年齡 div 不能
<!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"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title></head><script src="__PUBLIC__/js/jquery-1.11.2.min.js"></script><body><div>使用者名稱:<input type="text" id="uid" /></div>
<div><input type="button" value="註冊"id="btn"/></div
<script type="text/javascript">$("#btn").click(function(){ var uid = $("#uid").val(); //alert(uid); $.ajax({ url:"__CONTROLLER__/test", data:{uid:uid}, type:"POST", dataType:"TEXT", success:function(data){ alert(data); } }) })
//模板頁面
<?phpnamespace Home\Controller;use Think\Controller;class TestController extends Controller { public function test() { //var_dump($_POST); $y = D("zhuce"); //var_dump($y); //執行個體化對象 $arr = array( array("uid","require","使用者名稱不可為空"), ); if($y->validate($arr)->create()) { $this->ajaxReturn("通過驗證","eval"); //$y->add(); } else { $this->ajaxReturn($y->getError(),"eval"); } } public function tianjia() { $this->show(); }
//調方法顯示頁面:如果為空白顯示
<?phpnamespace Home\Model;use Think\Model;class ZhucCeModel extends Model{ protected $tablePrefix="";//表示表名沒有加首碼 protected $trueTableName="zhuce";//表示真實表名 protected $_validate = array( array("uid","require","使用者名稱不可為空"),//驗證使用者名稱不可為空 array(‘pwd‘,‘pw1‘,‘兩次輸入的密碼不一致‘,0,‘confirm‘),//驗證兩次輸入的密碼是否相同 array("youxiang","email","郵箱格式不正確"),//email是已經封裝好的通過(email) array("shengfenzheng",‘/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/‘,‘社會安全號碼不正確‘,0,‘regex‘),//通過正則(regex)來驗證 array(‘age‘,‘18,50‘,‘年齡不在範圍內‘,0,‘between‘),//驗證年齡 ); }
tp架構實現ajax註冊驗證 靜態驗證