Files
confirms/app/Libraries/FormValidation.php
yangsh 2c96bd12de
Some checks failed
Close Pull Request / main (pull_request_target) Has been cancelled
상세수정
2026-02-04 10:48:51 +09:00

57 lines
1.5 KiB
PHP

<?php
namespace App\Libraries;
class FormValidation
{
/**
* 한글, 영문, 숫자, 대시, 언더바만 가능하게 한다. utf-8 기준.
*
* @param string $str 검증할 문자열
* @param string|null $error 에러 메시지 (참조로 전달)
* @return bool
*/
public function korean_alpha_dash(string $str, ?string &$error = null): bool
{
if (!preg_match('/^[\x{1100}-\x{11FF}\x{3130}-\x{318F}\x{AC00}-\x{D7AF}0-9a-zA-Z_-]+$/u', $str)) {
$error = '한글, 영문, 숫자, 대시, 언더바만 입력 가능합니다.';
return false;
}
return true;
}
/**
* 문자열 형식이 Date가 맞는지 확인한다.
*
* @param string $str 검증할 날짜 문자열
* @param string $format 날짜 형식 (기본값: Y-m-d)
* @param string|null $error 에러 메시지 (참조로 전달)
* @return bool
*/
public function is_date(string $str, string $format = 'Y-m-d', ?string &$error = null): bool
{
try {
if (empty($format)) {
$format = 'Y-m-d';
}
$date = strtotime($str);
if ($date === false) {
$error = '올바른 날짜 형식이 아닙니다.';
return false;
}
$strDate = date($format, $date);
if (strcmp($str, $strDate) !== 0) {
$error = "날짜 형식이 {$format}와 일치하지 않습니다.";
return false;
}
} catch (\Exception $e) {
$error = '날짜 검증 중 오류가 발생했습니다.';
return false;
}
return true;
}
}