1
0

first commit

This commit is contained in:
2020-08-06 14:58:51 +08:00
commit 17096657dc
780 changed files with 92857 additions and 0 deletions

90
extend/tools/Verify.php Normal file
View File

@@ -0,0 +1,90 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace tools;
/**
* 校验工具类
*/
class Verify
{
/**
* 身份证号码校验
* @param string $idcard
* @return boolean
*/
public static function isIdcard($cardNo)
{
if (strlen($cardNo) != 18) {
return false;
}
$idcard_base = substr($cardNo, 0, 17);
$verify_code = substr($cardNo, 17, 1);
$factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
$verify_list = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
$total = 0;
for ($i = 0; $i < 17; $i++) {
$total += substr($idcard_base, $i, 1) * $factor[$i];
}
$mod = $total % 11;
if ($verify_code == $verify_list[$mod]) {
return true;
} else {
return false;
}
}
/**
* 检测手机号码格式
* @param string $mobile
* @return boolean
*/
public static function isMobilePhone($mobile)
{
if (preg_match("/^1[3578]{1}[0-9]{9}$|14[57]{1}[0-9]{8}$/", $mobile)) {
return true;
} else {
return false;
}
}
/**
* JSON校验
* @param string $jsonStr
* @return boolean
*/
public static function isJson($jsonStr)
{
if (!is_object(json_decode($jsonStr))) {
return false;
} else {
return true;
}
}
/**
* 校验日期格式是否合法
* @param [type] $date 日期
* @param string $rule 要校验的格式
* @return boolean
*/
public static function isDate($date, $rule = 'Y-m-d')
{
$unixTime = strtotime($date);
if (!$unixTime || date($rule, $unixTime) != $date) {
return false;
} else {
return true;
}
}
}