-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_by_wangyuan.php
More file actions
112 lines (101 loc) · 2.46 KB
/
test_by_wangyuan.php
File metadata and controls
112 lines (101 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
define("APP_PATH", dirname(__FILE__));
spl_autoload_register(function ($className) {
$className = str_replace("Crazymus\\", "src\\", $className);
$filePath = APP_PATH . '/' . $className . '.php';
// mac, linux, window 路径分隔符统一
$filePath = str_replace("\\", DIRECTORY_SEPARATOR, $filePath);
if (file_exists($filePath)) {
require_once $filePath;
}
});
$params = array(
'name' => '用户名用户名',
'age' => 19,
'sex' => 2,
'ratio' => "0.9",
'money' => 100.23,
'job' => 'Engineer',
'email' => 'crazymus@foxmail.com',
'phone' => 18507105403,
'site' => 'https://www.baidu.com/user/index?id=3&name=crazymus',
'hobby' => 'music'
);
$rules = array(
'name' => array(
'title' => '姓名',
'required' => true,
'length' => array(
array('>', 5),
array('<=', 6)
),
'charset' => 'utf-8'
),
'age' => array(
'type' => 'integer',
'title' => '年龄',
'required' => true,
'value' => array('>=', 18)
),
'sex' => array(
'type' => 'number',
'title' => '性别',
'required' => true,
'enum' => array(1, 2),
'errorMsg' => '性别格式错误'
),
'money' => array(
'type' => 'money',
'title' => '金额',
'required' => true,
'value' => array('>', 100)
),
'job' => array(
'title' => '职业',
'required' => false,
),
'email' => array(
'type' => 'email',
'title' => '邮箱',
'required' => true
),
'phone' => array(
'type' => 'phone',
'title' => '手机号',
'required' => true
),
'site' => array(
'type' => 'url',
'title' => '网址',
'required' => true
),
'ratio' => array(
'type' => 'float',
'title' => '比率',
'required' => true,
'precision' => 2
),
'hobby' => array(
'type' => 'myRule',
'title' => '爱好',
'required' => true,
)
);
// 添加自定义规则
//\Crazymus\Pvalidate::addRules('myRule', 'MyRule');
\Crazymus\Pvalidate::addRules(array(
'myRule' => '\Crazymus\customRule\MyRule'
));
try {
$validateParams = \Crazymus\Pvalidate::validate($params, $rules);
pp($validateParams);
} catch (\Exception $e) {
echo $e->getMessage();
}
function pp($array)
{
echo "<pre>";
print_r($array);
echo "</pre>";
exit;
}