This commit is contained in:
Enoch
2024-08-09 22:16:39 +08:00
commit d78b38e80f
3984 changed files with 416946 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Respect\Validation\Rules;
use libphonenumber\NumberParseException;
use function is_scalar;
final class Mobile extends AbstractRule
{
/**
* {@inheritDoc}
*/
public function validate($input): bool
{
if (!is_scalar($input)) {
return false;
}
try {
// 此处使用简单的正则表达式检查中国大陆的手机号码格式
return preg_match('/^1[3456789]\d{9}$/', (string) $input) === 1;
} catch (NumberParseException $e) {
return false;
}
}
}