mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-05 22:52:49 +08:00
Validate类增加rule方法用于设置全局正则验证规则
This commit is contained in:
@@ -13,6 +13,7 @@ namespace think;
|
||||
|
||||
class Validate
|
||||
{
|
||||
// 预定义正则验证规则
|
||||
protected static $rule = [
|
||||
'require' => '/\S+/',
|
||||
'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
|
||||
@@ -24,8 +25,26 @@ class Validate
|
||||
'double' => '/^[-\+]?\d+(\.\d+)?$/',
|
||||
'english' => '/^[A-Za-z]+$/',
|
||||
];
|
||||
|
||||
// 验证失败错误信息
|
||||
protected static $error = [];
|
||||
|
||||
/**
|
||||
* 设置正则验证规则
|
||||
* @access protected
|
||||
* @param string|array $name 规则名称或者规则数组
|
||||
* @param string $rule 正则规则
|
||||
* @return void
|
||||
*/
|
||||
public static function rule($name, $rule = '')
|
||||
{
|
||||
if (is_array($name)) {
|
||||
self::$rule = array_merge(self::$rule, $name);
|
||||
} else {
|
||||
self::$rule[$name] = $rule;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据自动验证
|
||||
* @access protected
|
||||
|
||||
Reference in New Issue
Block a user