1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-22 19:44:02 +08:00
koogua a7f197c01b !6 develop->master 1.1.0
* 更新版本号
* 完善后台今日统计,增加权限白名单,增加后台首页菜单,调整后台登录页样式
* Merge branch 'koogua/I1XFCF' of https://gitee.com/koogua/course-tencen…
* 前台学习资料部分完成
* !2 后台运营统计合并
* 后台学习资料部分完成
* Merge branch 'master' into develop
* Merge branch 'master' of https://github.com/xiaochong0302/course-tencent-cloud
* 1.增加changelog.md
* 1.简化部分路由地址
* Merge pull request #2 from xiaochong0302/dependabot/composer/symfony/h…
* Bump symfony/http-foundation from 4.3.4 to 5.1.6
2020-10-08 18:44:06 +08:00

113 lines
2.3 KiB
PHP

<?php
namespace App\Library\Validators;
class Common
{
public static function in($needle, $haystack)
{
return in_array($needle, $haystack);
}
public static function between($value, $min, $max)
{
return $max >= $value && $min <= $value;
}
public static function equals($a, $b)
{
return $a == $b;
}
public static function email($str)
{
return filter_var($str, FILTER_VALIDATE_EMAIL) !== false;
}
public static function url($str)
{
if (strpos($str, '//') === 0) {
$str = 'http:' . $str;
}
return filter_var($str, FILTER_VALIDATE_URL) !== false;
}
public static function intNumber($value)
{
return filter_var($value, FILTER_VALIDATE_INT) !== false;
}
public static function floatNumber($value)
{
if (filter_var($value, FILTER_VALIDATE_FLOAT) === false) {
return false;
}
if (strpos($value, '.') === false) {
return false;
}
$head = strstr($value, '.', true);
if ($head[0] == '0' && strlen($head) > 1) {
return false;
}
return true;
}
public static function positiveNumber($value)
{
if (!self::intNumber($value)) {
return false;
}
return $value > 0;
}
public static function idCard($str)
{
$validator = new IdCard();
return $validator->validate($str);
}
public static function phone($str)
{
$pattern = '/^1(3|4|5|6|7|8|9)[0-9]{9}$/';
return preg_match($pattern, $str) ? true : false;
}
public static function name($str)
{
$pattern = '/^[\x{4e00}-\x{9fa5}A-Za-z0-9]{2,15}$/u';
return preg_match($pattern, $str) ? true : false;
}
public static function password($str)
{
$pattern = '/^[[:graph:]]{6,16}$/';
return preg_match($pattern, $str) ? true : false;
}
public static function birthday($str)
{
$pattern = '/^(19|20)\d{2}-(1[0-2]|0[1-9])-(0[1-9]|[1-2][0-9]|3[0-1])$/';
return preg_match($pattern, $str) ? true : false;
}
public static function date($str, $format = 'Y-m-d')
{
$date = date($format, strtotime($str));
return $str == $date;
}
}