123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?php
- namespace Common\Server;
- use Common\Server\BaseServer;
- /**
- * 正则表达式等相关 server
- */
- class RegularServer extends BaseServer {
- /**
- * 判断登录密码格式是否正确
- * @param type $password 登录密码
- * @return string4
- */
- public function check_password($password) {
- if(empty($password)){
- jsonReturn(1001, '密码不能为空');
- }
- $password = trim($password);
- if (!preg_match('/^(?=.*[^\d]).{6,16}$/', $password)) {
- jsonReturn(1032, '密码由6-16位非纯数字组成');
- } else {
- //判断是否包含中文
- if (preg_match("/[\x7f-\xff]/", $password)) {
- jsonReturn(1001, '密码请不要包含中文'); //含有中文
- }
- }
- return true;
- }
- /**
- * 判断登录密码格式是否正确
- * @param type $password 登录密码
- * @return string4
- */
- public function m_check_password($password) {
- if(empty($password)){
- return array('code' => 1001, 'msg' => '密码不能为空');
- }
- $password = trim($password);
- if (!preg_match('/^(?=.*[^\d]).{6,16}$/', $password)) {
- return array('code' => 1032, 'msg' => '密码由6-16位非纯数字组成');
- } else {
- //判断是否包含中文
- if (preg_match("/[\x7f-\xff]/", $password)) {
- return array('code' => 1001, 'msg' => '密码请不要包含中文');//含有中文
- }
- }
- return array('code' => 1000, 'msg' => '密码验证通过');
- }
- /**
- * 判断支付密码格式是否正确
- * @param type $password 登录密码
- * @return string4
- */
- public function check_pay_password($password) {
- if(empty($password)){
- jsonReturn(1001, '密码不能为空');
- }
- $password = trim($password);
- if (!preg_match('/^[0-9]\d{5}$/', $password)) {
- jsonReturn(1089, '支付密码由6位纯数字组成');
- } else {
- //判断是否包含中文
- if (preg_match("/[\x7f-\xff]/", $password)) {
- jsonReturn(1001, '支付密码请不要包含中文'); //含有中文
- }
- }
- return true;
- }
- /**
- * 验证用户名
- * @param $username
- */
- public function check_username($username) {
- $username = trim($username);
- if (preg_match("/\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\\|\|/", $username)) {
- jsonReturn(1001, '用户名不能包含特殊字符');
- }
- return true;
- }
- /**
- * 判断交易密码格式是否正确
- * @param type $password 交易密码
- * @return string
- */
- public function checkPayPwd($password) {
- $password = trim($password);
- //验证纯数字
- if (!preg_match('/^\d{6}$/', $password)) {
- return CpError(CP_ERROR, '支付密码由6位纯数字组成');
- } else {
- return CpSuccess('ok');
- }
- }
-
- /**
- * 判断手机号码是否正确
- * @param type $tel 手机号码
- * @return string
- */
- public function check_tel($tel) {
- $tel = trim($tel);
- if (!preg_match('/^1\d{10}$/', $tel)) {
- return false;
- } else {
- return true;
- }
- }
-
- /**
- * 判断身份证号码是否正确
- * @param type $card_id 手机号码
- * @return string
- */
- public function checkCardId($card_id) {
- $card_id = trim($card_id);
- if (!preg_match('/^[a-zA-Z0-9]{15,20}$/', $card_id)) {
- return CpError(CP_ERROR, '身份证号码不正确');
- } else {
- return CpSuccess('ok');
- }
- }
-
- /**
- * 判断银行卡号码是否正确
- * @param type $bank_id 身份证号码
- * @return string
- */
- public function checkBankNo($bank_id) {
- $bank_id = trim($bank_id);
- if (!preg_match('/^[0-9]{16,20}$/', $bank_id)) {
- return CpError(CP_ERROR, '银行卡号码不正确');
- } else {
- return CpSuccess('ok');
- }
- }
- /**
- * @param $username
- */
- public function check_user_name($username) {
- if(empty($username)){
- jsonReturn(B_USERNAME_NULL, '用户名不能为空');
- }
- $username = trim($username);
- if (!preg_match('/^(?=.*[^\d]).{1,50}$/', $username)) {
- jsonReturn(B_USERNAME_LETTER_NUM, '用户名必须由字母及数字组成');
- } else {
- //判断是否包含中文
- if (preg_match("/[\x7f-\xff]/", $username)) {
- jsonReturn(B_USERNAME_ZH, '用户名请不要包含中文'); //含有中文
- }
- }
- }
- /**
- * 判断手机号码是否正确
- * @param type $tel 手机号码
- */
- public function check_binsiness_tel($tel) {
- $tel = trim($tel);
- if (!preg_match('/^1\d{10}$/', $tel)) {
- jsonReturn(B_TEL_ERROR, '手机号码不正确');
- }
- }
- /**
- * 判断联系方式是否正确
- * @param type $tel 手机号码或座机号
- */
- public function check_contact_tel($tel) {
- $tel = trim($tel);
- if (preg_match('/^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$/', $tel)) {//判断座机号
- return true;
- }
- if (preg_match('/^1\d{10}$/', $tel)) {//判断手机号
- return true;
- }
- return false;
- }
- /**
- * 判断是否手机端访问
- * @author: linch
- * @return bool
- */
- function is_mobile_request() {
- $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';
- $mobile_browser = '0';
- if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))
- $mobile_browser++;
- if ((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']), 'application/vnd.wap.xhtml+xml') !== false))
- $mobile_browser++;
- if (isset($_SERVER['HTTP_X_WAP_PROFILE']))
- $mobile_browser++;
- if (isset($_SERVER['HTTP_PROFILE']))
- $mobile_browser++;
- $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4));
- $mobile_agents = array(
- 'w3c ', 'acs-', 'alav', 'alca', 'amoi', 'audi', 'avan', 'benq', 'bird', 'blac',
- 'blaz', 'brew', 'cell', 'cldc', 'cmd-', 'dang', 'doco', 'eric', 'hipt', 'inno',
- 'ipaq', 'java', 'jigs', 'kddi', 'keji', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-',
- 'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp', 'nec-',
- 'newt', 'noki', 'oper', 'palm', 'pana', 'pant', 'phil', 'play', 'port', 'prox',
- 'qwap', 'sage', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh-', 'shar',
- 'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-',
- 'tosh', 'tsm-', 'upg1', 'upsi', 'vk-v', 'voda', 'wap-', 'wapa', 'wapi', 'wapp',
- 'wapr', 'webc', 'winw', 'winw', 'xda', 'xda-'
- );
- if (in_array($mobile_ua, $mobile_agents))
- $mobile_browser++;
- if (strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)
- $mobile_browser++;
- // Pre-final check to reset everything if the user is on Windows
- if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)
- $mobile_browser = 0;
- // But WP7 is also Windows, with a slightly different characteristic
- if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)
- $mobile_browser++;
- if ($mobile_browser > 0)
- return true;
- else
- return false;
- }
- }
|