<?php class preg { public function telP($tel) { $preg = '/^1[34578]\d{9}$/'; $res = preg_match($preg, $tel); if(!$res){ myNotice('手機號碼格式不正確!'); } } public function strP($str) { $preg = '/[\<\>\'\"]/'; $res = preg_match($preg, $str); if($res){ myNotice('不能含有引號或括號'); } } public function numP($num,$name='') { $preg = '/^\d{1,8}$/'; $res = preg_match($preg, $num); if(!$res){ myNotice($name.'只能是8位純數字'); } $this->strP($num); } public function priceP($pri) { $preg = '/^\d{1,8}\.?\d{0,2}$/'; $res = preg_match($preg, $pri); if(!$res){ myNotice('單價格式不正確'); } $this->strP($num); } public function pwdP($pwd) { $preg = '/^\w{3,12}$/'; $res = preg_match($preg, $pwd); if(!$res){ myNotice('密碼只能是3到12位的數字,字母,下劃線'); } } }
以上是驗證類的源碼php
調用this
使用3d