2016-07-18 16:39:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function validateUsername($username) {
|
|
|
|
return is_string($username) && preg_match('/^[a-zA-Z0-9_]{1,20}$/', $username);
|
|
|
|
}
|
|
|
|
|
|
|
|
function validatePassword($password) {
|
|
|
|
return is_string($password) && preg_match('/^[a-z0-9]{32}$/', $password);
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateEmail($email) {
|
|
|
|
return is_string($email) && strlen($email) <= 50 && preg_match('/^(.+)@(.+)$/', $email);
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateQQ($QQ) {
|
|
|
|
return is_string($QQ) && strlen($QQ) <= 15 && preg_match('/^[0-9]{5,15}$/', $QQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateMotto($motto) {
|
2022-09-18 13:38:57 +00:00
|
|
|
return is_string($motto) && ($len = mb_strlen($motto, 'UTF-8')) !== false && $len <= 1024;
|
2016-07-18 16:39:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 06:59:26 +00:00
|
|
|
function validateUInt($x, $len = 8) { // [0, 1000000000)
|
2016-07-18 16:39:37 +00:00
|
|
|
if (!is_string($x)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($x === '0') {
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-14 06:59:26 +00:00
|
|
|
return preg_match('/^[1-9][0-9]{0,'.$len.'}$/', $x);
|
2016-07-18 16:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function validateInt($x) {
|
|
|
|
if (!is_string($x)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($x[0] == '-') {
|
|
|
|
$x = substr($x, 1);
|
|
|
|
}
|
|
|
|
return validateUInt($x);
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateUploadedFile($name) {
|
|
|
|
return isset($_FILES[$name]) && is_uploaded_file($_FILES[$name]['tmp_name']);
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateIP($ip) {
|
|
|
|
return filter_var($ip, FILTER_VALIDATE_IP) !== false;
|
|
|
|
}
|
2022-09-21 03:33:42 +00:00
|
|
|
|
|
|
|
function validateURL($url) {
|
|
|
|
return filter_var($url, FILTER_VALIDATE_URL) !== false;
|
|
|
|
}
|
2022-10-12 13:10:07 +00:00
|
|
|
|
|
|
|
function validateString($str) {
|
|
|
|
return preg_match('/[^0-9a-zA-Z]/', $str) !== true;
|
|
|
|
}
|
2022-10-19 14:16:10 +00:00
|
|
|
|
|
|
|
function validateGitHubUsername($username) {
|
|
|
|
return is_string($username) && preg_match('/^[a-zA-Z0-9_-]{1,20}$/', $username);
|
|
|
|
}
|
2022-11-06 02:26:21 +00:00
|
|
|
|
|
|
|
function validateUserAndStoreByUsername($username, &$vdata) {
|
|
|
|
if (!isset($vdata['user'])) {
|
|
|
|
$vdata['user'] = [];
|
|
|
|
}
|
|
|
|
$user = UOJUser::query($username);
|
|
|
|
if (!$user) {
|
|
|
|
return "不存在名为{$username}的用户";
|
|
|
|
}
|
|
|
|
$vdata['user'][$username] = $user;
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_short_string($str) {
|
|
|
|
return is_string($str) && strlen($str) <= 256;
|
|
|
|
}
|
2023-01-18 08:20:12 +00:00
|
|
|
|
|
|
|
function validateCodeforcesProblemId($str) {
|
2023-01-20 09:13:39 +00:00
|
|
|
return preg_match('/(|GYM)[1-9][0-9]{0,5}[A-Z][1-9]?/', $str) !== true;
|
2023-01-18 08:20:12 +00:00
|
|
|
}
|