Laravel validate 500异常 添加手机验证,中文验证与Validator验证的“半个”生命周期
今天来讲一下,Lumen的Validator函数
|
1
2
3
4
5
6
7
8
9
10
11
|
use Validator;...Class .. {public function ..(){ Validator::make($input, $rules, $message, $attributes)->validate();} |
|
1
|
use Validator是可以直接引用的,虽然不能直接找到该命名空间的对应的位置。也可以直接在控制器use和使用Validator::make()。 |
|
1
|
<em>至于类名和函数名就随意啦,$input为传入验证的数组,$rule为验证规则,$message为返回的规则,</em>$attributes为验证字段的对应中文注释。废话少说,先模拟一个标准的数据, |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
$input = [ 'typeid' => 1, 'title' => '测试标题', 'content' => '测试内容'];$rules = [ 'typeid' => 'required|numeric', 'title' => 'required', 'content' => 'required'];$message = [ "required" => ":attribute 不能为空", "numeric" => ":attribute 格式不正确"];$attributes = [ 'typeid' => '分类id', 'title' => '标题', 'content' => '内容']; |
执行后,可能报错Illuminate\Validation\ValidationException: The given data failed to pass validation ...... vendor\illuminate\validation\Validator.php on line305
这是Lumen的异常处理机制,vendor\illuminate\validation\Validator.php
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
/** * Run the validator's rules against its data.(运行验证的规则对数据。) * * @return void * * @throws \Illuminate\Validation\ValidationException */ public function validate() { if ($this->fails()) { throw new ValidationException($this); } } |
看看vendor\illuminate\validation\ValidationException.php
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
class ValidationException extends Exception{ ... /** * Create a new exception instance.(创建一个新的异常实例。) * * @param \Illuminate\Contracts\Validation\Validator $validator * @param \Symfony\Component\HttpFoundation\Response $response * @return void */ public function __construct($validator, $response = null) { parent::__construct('The given data failed to pass validation.'); $this->response = $response; $this->validator = $validator;} |
直接这样抛出异常肯定不ok,接下看看解决方法,
方法一,异常拦截
进入app\Exceptions\Hanlder.php
|
1
2
3
4
5
6
7
8
9
|
public function render($request, Exception $e){ //自带数据验证错误返回 if ($e instanceof \Illuminate\Validation\ValidationException) { return $this->handleValidationException($request, $e); } return parent::render($request, $e);}<br data-filtered="filtered"><br data-filtered="filtered"> |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
//获取自带数据验证错误信息protected function handleValidationException($request, $e){ $errors = @$e->validator->errors()->toArray(); $message = null; if (count($errors)) { $firstKey = array_keys($errors)[0]; $message = @$e->validator->errors()->get($firstKey)[0]; if (strlen($message) == 0) { $message = "An error has occurred when trying to register"; } } if ($message == null) { $message = "An unknown error has occured"; } return $message;} |
结果会返回第一个验证不过的对应信息。
不过直接在异常这里做处理不太合理,方法二
|
1
2
3
4
5
6
7
8
|
//Validator::make($input, $rules , $message, $attributes)->validate();$validator = Validator::make($input, $rules, $message, $attributes);$failed = $validator->failed();$messages = $validator->messages();if(count($messages) != 0){ dataReturn(1,current(current($messages))[0]);} |
调用failed和messages方法来处理会优雅许多!
接下来说一下大家关心的手机验证,
|
1
2
3
|
Validator::extend('mobile', function($attribute, $value, $parameters) { return preg_match("/^1[34578]{1}\d{9}$/",$value); }); |
|
1
|
<span style="font-size: 14px; line-height: 21px; white-space: normal"><span style="font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif">这段代码应该很熟悉吧,不过到底放在哪里合适呢?我是这么做的<br data-filtered="filtered"><br data-filtered="filtered">bootstrap/app.phpj加上<br data-filtered="filtered"></span></span> |
|
1
|
$app->register(App\Providers\Validate\ValidateServiceProvider::class); |
|
1
|
|
然后创建对应服务类app/Providers/Validate/ValidateServiceProvider.php
|
1
|
|
|
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
|
<?phpnamespace App\Providers\Validate;use Validator;use Illuminate\Support\ServiceProvider;class ValidateServiceProvider extends ServiceProvider{ /** * 启动应用服务 * * @return void */ public function boot() { Validator::extend('mobile', function($attribute, $value, $parameters) { return preg_match("/^1[34578]{1}\d{9}$/",$value); }); } /** * Register any application services. * * @return void */ public function register() { }} |
加入手机验证
|
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
|
$input = [ 'typeid' => 1, 'title' => '测试标题', 'content' => '测试内容', 'phone' => '1881'];$rules = [ 'typeid' => 'required|numeric', 'title' => 'required', 'content' => 'required', 'phone' => 'mobile'];$message = [ "required" => ":attribute 不能为空", "numeric" => ":attribute 格式不正确", "mobile" => ":attribute 手机格式不正确"];$attributes = [ 'typeid' => '分类id', 'title' => '标题', 'content' => '内容', 'phone' => '联系方式']; |
就这样简单的实现了手机验证!
如果不想每次都传$message的话,可以看看这里\vendor\laravel\lumen-framework\resources\lang\en\validation.php
|
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
112
113
114
115
116
117
118
119
|
<?phpreturn [ /* |-------------------------------------------------------------------------- | Validation Language Lines |-------------------------------------------------------------------------- | | The following language lines contain the default error messages used by | the validator class. Some of these rules have multiple versions such | as the size rules. Feel free to tweak each of these messages here. | */ 'accepted' => 'The :attribute must be accepted.', 'active_url' => 'The :attribute is not a valid URL.', 'after' => 'The :attribute must be a date after :date.', 'after_or_equal' => 'The :attribute must be a date after or equal to :date.', 'alpha' => 'The :attribute may only contain letters.', 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', 'alpha_num' => 'The :attribute may only contain letters and numbers.', 'array' => 'The :attribute must be an array.', 'before' => 'The :attribute must be a date before :date.', 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', 'between' => [ 'numeric' => 'The :attribute must be between :min and :max.', 'file' => 'The :attribute must be between :min and :max kilobytes.', 'string' => 'The :attribute must be between :min and :max characters.', 'array' => 'The :attribute must have between :min and :max items.', ], 'boolean' => 'The :attribute field must be true or false.', 'confirmed' => 'The :attribute confirmation does not match.', 'date' => 'The :attribute is not a valid date.', 'date_format' => 'The :attribute does not match the format :format.', 'different' => 'The :attribute and :other must be different.', 'digits' => 'The :attribute must be :digits digits.', 'digits_between' => 'The :attribute must be between :min and :max digits.', 'dimensions' => 'The :attribute has invalid image dimensions.', 'distinct' => 'The :attribute field has a duplicate value.', 'email' => 'The :attribute must be a valid email address.', 'exists' => 'The selected :attribute is invalid.', 'file' => 'The :attribute must be a file.', 'filled' => 'The :attribute field is required.', 'image' => 'The :attribute must be an image.', 'in' => 'The selected :attribute is invalid.', 'in_array' => 'The :attribute field does not exist in :other.', 'integer' => 'The :attribute must be an integer.', 'ip' => 'The :attribute must be a valid IP address.', 'json' => 'The :attribute must be a valid JSON string.', 'max' => [ 'numeric' => 'The :attribute may not be greater than :max.', 'file' => 'The :attribute may not be greater than :max kilobytes.', 'string' => 'The :attribute may not be greater than :max characters.', 'array' => 'The :attribute may not have more than :max items.', ], 'mimes' => 'The :attribute must be a file of type: :values.', 'mimetypes' => 'The :attribute must be a file of type: :values.', 'min' => [ 'numeric' => 'The :attribute must be at least :min.', 'file' => 'The :attribute must be at least :min kilobytes.', 'string' => 'The :attribute must be at least :min characters.', 'array' => 'The :attribute must have at least :min items.', ], 'not_in' => 'The selected :attribute is invalid.', 'numeric' => 'The :attribute must be a number.', 'present' => 'The :attribute field must be present.', 'regex' => 'The :attribute format is invalid.', 'required' => 'The :attribute field is required.', 'required_if' => 'The :attribute field is required when :other is :value.', 'required_unless' => 'The :attribute field is required unless :other is in :values.', 'required_with' => 'The :attribute field is required when :values is present.', 'required_with_all' => 'The :attribute field is required when :values is present.', 'required_without' => 'The :attribute field is required when :values is not present.', 'required_without_all' => 'The :attribute field is required when none of :values are present.', 'same' => 'The :attribute and :other must match.', 'size' => [ 'numeric' => 'The :attribute must be :size.', 'file' => 'The :attribute must be :size kilobytes.', 'string' => 'The :attribute must be :size characters.', 'array' => 'The :attribute must contain :size items.', ], 'string' => 'The :attribute must be a string.', 'timezone' => 'The :attribute must be a valid zone.', 'unique' => 'The :attribute has already been taken.', 'uploaded' => 'The :attribute failed to upload.', 'url' => 'The :attribute format is invalid.', /* |-------------------------------------------------------------------------- | Custom Validation Language Lines |-------------------------------------------------------------------------- | | Here you may specify custom validation messages for attributes using the | convention "attribute.rule" to name the lines. This makes it quick to | specify a specific custom language line for a given attribute rule. | */ 'custom' => [ 'attribute-name' => [ 'rule-name' => 'custom-message', ], ], /* |-------------------------------------------------------------------------- | Custom Validation Attributes |-------------------------------------------------------------------------- | | The following language lines are used to swap attribute place-holders | with something more reader friendly such as E-Mail Address instead | of "email". This simply helps us make messages a little cleaner. | */ 'attributes' => [],]; |
默认都是英文,直接改成下面的中文配置
|
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
112
113
114
115
116
117
118
|
<?phpreturn [/*|--------------------------------------------------------------------------| Validation Language Lines|--------------------------------------------------------------------------|| The following language lines contain the default error messages used by| the validator class. Some of these rules have multiple versions such| as the size rules. Feel free to tweak each of these messages here.|*/'accepted' => ':attribute必须接受','active_url' => ':attribute必须是一个合法的 URL','after' => ':attribute 必须是 :date 之后的一个日期','after_or_equal' => ':attribute 必须是 :date 之后或相同的一个日期','alpha' => ':attribute只能包含字母','alpha_dash' => ':attribute只能包含字母、数字、中划线或下划线','alpha_num' => ':attribute只能包含字母和数字','array' => ':attribute必须是一个数组','before' => ':attribute 必须是 :date 之前的一个日期','before_or_equal' => ':attribute 必须是 :date 之前或相同的一个日期','between' => [ 'numeric' => ':attribute 必须在 :min 到 :max 之间', 'file' => ':attribute 必须在 :min 到 :max KB 之间', 'string' => ':attribute 必须在 :min 到 :max 个字符之间', 'array' => ':attribute 必须在 :min 到 :max 项之间',],'boolean' => ':attribute 字符必须是 true 或 false','confirmed' => ':attribute 二次确认不匹配','date' => ':attribute 必须是一个合法的日期','date_format' => ':attribute 与给定的格式 :format 不符合','different' => ':attribute 必须不同于 :other','digits' => ':attribute必须是 :digits 位.','digits_between' => ':attribute 必须在 :min 和 :max 位之间','dimensions' => ':attribute具有无效的图片尺寸','distinct' => ':attribute字段具有重复值','email' => ':attribute必须是一个合法的电子邮件地址','exists' => '选定的 :attribute 是无效的.','file' => ':attribute必须是一个文件','filled' => ':attribute的字段是必填的','image' => ':attribute必须是 jpeg, png, bmp 或者 gif 格式的图片','in' => '选定的 :attribute 是无效的','in_array' => ':attribute 字段不存在于 :other','integer' => ':attribute 必须是个整数','ip' => ':attribute必须是一个合法的 IP 地址。','json' => ':attribute必须是一个合法的 JSON 字符串','max' => [ 'numeric' => ':attribute 的最大长度为 :max 位', 'file' => ':attribute 的最大为 :max', 'string' => ':attribute 的最大长度为 :max 字符', 'array' => ':attribute 的最大个数为 :max 个.',],'mimes' => ':attribute 的文件类型必须是 :values','min' => [ 'numeric' => ':attribute 的最小长度为 :min 位', 'file' => ':attribute 大小至少为 :min KB', 'string' => ':attribute 的最小长度为 :min 字符', 'array' => ':attribute 至少有 :min 项',],'not_in' => '选定的 :attribute 是无效的','numeric' => ':attribute 必须是数字','present' => ':attribute 字段必须存在','regex' => ':attribute 格式是无效的','required' => ':attribute 字段是必须的','required_if' => ':attribute 字段是必须的当 :other 是 :value','required_unless' => ':attribute 字段是必须的,除非 :other 是在 :values 中','required_with' => ':attribute 字段是必须的当 :values 是存在的','required_with_all' => ':attribute 字段是必须的当 :values 是存在的','required_without' => ':attribute 字段是必须的当 :values 是不存在的','required_without_all' => ':attribute 字段是必须的当 没有一个 :values 是存在的','same' => ':attribute和:other必须匹配','size' => [ 'numeric' => ':attribute 必须是 :size 位', 'file' => ':attribute 必须是 :size KB', 'string' => ':attribute 必须是 :size 个字符', 'array' => ':attribute 必须包括 :size 项',],'string' => ':attribute 必须是一个字符串','timezone' => ':attribute 必须是个有效的时区.','unique' => ':attribute 已存在','url' => ':attribute 无效的格式','mobile' => ':attribute 手机号码无效',/*|--------------------------------------------------------------------------| Custom Validation Language Lines|--------------------------------------------------------------------------|| Here you may specify custom validation messages for attributes using the| convention "attribute.rule" to name the lines. This makes it quick to| specify a specific custom language line for a given attribute rule.|*/'custom' => [ 'attribute-name' => [ 'rule-name' => 'custom-message', ],],/*|--------------------------------------------------------------------------| Custom Validation Attributes|--------------------------------------------------------------------------|| The following language lines are used to swap attribute place-holders| with something more reader friendly such as E-Mail Address instead| of "email". This simply helps us make messages a little cleaner.|*/'attributes' => [],]; |
然后在没有传$message时,就会默认读这里了!
接下来讲讲Lumen验证的周期,当你调用下面的语句时,
|
1
|
|
|
1
|
Validator::make($input, $rules, $message, $attributes); |
|
1
|
|
会直接调用到对应的Factory.php,这可以说是一种规范,这里是vendor\illuminate\validation\Factory.php,看看对应的make函数
|
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
|
/** * 创建一个新的验证实例。 */public function make(array $data, array $rules, array $messages = [], array $customAttributes = []){ // The presence verifier is responsible for checking the unique and exists data // for the validator. It is behind an interface so that multiple versions of // it may be written besides database. We'll inject it into the validator. $validator = $this->resolve( $data, $rules, $messages, $customAttributes ); if (! is_null($this->verifier)) { $validator->setPresenceVerifier($this->verifier); } // Next we'll set the IoC container instance of the validator, which is used to // resolve out class based validator extensions. If it is not set then these // types of extensions will not be possible on these validation instances. if (! is_null($this->container)) { $validator->setContainer($this->container); } $this->addExtensions($validator); return $validator;} |
然后来到resolve函数,
|
1
2
3
4
5
6
7
8
9
10
11
|
/** * 解决一个新的验证实例。 */protected function resolve(array $data, array $rules, array $messages, array $customAttributes){ if (is_null($this->resolver)) { return new Validator($this->translator, $data, $rules, $messages, $customAttributes); } return call_user_func($this->resolver, $this->translator, $data, $rules, $messages, $customAttributes);} |
|
1
|
|
|
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
|
namespace Illuminate\Validation;..class Validator implements ValidatorContract{... /** * Create a new Validator instance.(创建一个新的验证实例。) */ public function __construct(Translator $translator, array $data, array $rules, array $messages = [], array $customAttributes = []) { $this->initialRules = $rules; $this->translator = $translator; $this->customMessages = $messages; $this->data = $this->parseData($data); $this->customAttributes = $customAttributes; $this->setRules($rules); }} |
make执行到这里完。
接下来,先来看看刚才用的第一个验证函数validate(),
|
1
2
3
4
5
6
7
8
9
|
/** * Run the validator's rules against its data.(运行验证的规则对数据。) */public function validate(){ if ($this->fails()) { throw new ValidationException($this); }} |
|
1
2
3
4
5
6
|
/** * Determine if the data fails the validation rules.(确定数据验证失败的规则。确定数据验证失败的规则。)<br data-filtered="filtered"> * @return bool */ public function fails() { return ! $this->passes();//稍后分析 |
|
1
|
} |
显而易见,一旦验证不通过则抛出异常,不太适合一般的开发。
再看看messages()
|
1
2
3
4
5
6
7
8
9
10
11
|
/** * Get the message container for the validator.(得到验证消息的容器。) */public function messages(){ if (! $this->messages) { $this->passes();//稍后分析 } return $this->messages;} |
这里函数是返回所有验证不通过的信息
再看看failed()
|
1
2
3
4
5
6
7
8
9
|
/** * Get the failed validation rules.(获取失败的验证规则。) * * @return array */ public function failed() { return $this->failedRules; } |
这边好像验证失败也是空,晕~
接下来看passes()
|
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
|
/** * Determine if the data passes the validation rules.(确定数据验证规则) * * @return bool */ public function passes() { $this->messages = new MessageBag; // We'll spin through each rule, validating the attributes attached to that // rule. Any error messages will be added to the containers with each of // the other error messages, returning true if we don't have messages. foreach ($this->rules as $attribute => $rules) { $attribute = str_replace('\.', '->', $attribute); foreach ($rules as $rule) { $this->validateAttribute($attribute, $rule); if ($this->shouldStopValidating($attribute)) { break; } } } // Here we will spin through all of the "after" hooks on this validator and // fire them off. This gives the callbacks a chance to perform all kinds // of other validation that needs to get wrapped up in this operation. foreach ($this->after as $after) { call_user_func($after); } return $this->messages->isEmpty(); } |
接下来干货来了validateAttribute($attribute, $rule)函数,处理都在这里调的
|
1
2
|
/** * Validate a given attribute against a rule.(根据规则验证给定属性。) |
|
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
|
* * @param string $attribute * @param string $rule * @return void */protected function validateAttribute($attribute, $rule){ $this->currentRule = $rule; list($rule, $parameters) = ValidationRuleParser::parse($rule); if ($rule == '') { return; } // First we will get the correct keys for the given attribute in case the field is nested in // an array. Then we determine if the given rule accepts other field names as parameters. // If so, we will replace any asterisks found in the parameters with the correct keys. if (($keys = $this->getExplicitKeys($attribute)) && $this->dependsOnOtherFields($rule)) { $parameters = $this->replaceAsterisksInParameters($parameters, $keys); } $value = $this->getValue($attribute); // If the attribute is a file, we will verify that the file upload was actually successful // and if it wasn't we will add a failure for the attribute. Files may not successfully // upload if they are too large based on PHP's settings so we will bail in this case. if ($value instanceof UploadedFile && ! $value->isValid() && $this->hasRule($attribute, array_merge($this->fileRules, $this->implicitRules)) ) { return $this->addFailure($attribute, 'uploaded', []); } // If we have made it this far we will make sure the attribute is validatable and if it is // we will call the validation method with the attribute. If a method returns false the // attribute is invalid and we will add a failure message for this failing attribute. $validatable = $this->isValidatable($rule, $attribute, $value); $method = "validate{$rule}"; if ($validatable && ! $this->$method($attribute, $value, $parameters, $this)) { $this->addFailure($attribute, $rule, $parameters); }} |
主要是这两段
|
1
2
3
4
5
|
$method = "validate{$rule}"; if ($validatable && ! $this->$method($attribute, $value, $parameters, $this)) { $this->addFailure($attribute, $rule, $parameters); } |
根据规则拼接验证函数名,再调用,函数都写在了最开始引用的Concerns\ValidatesAttributes
|
1
2
|
use Concerns\FormatsMessages, Concerns\ValidatesAttributes; |
vendor\illuminate\validation\Concerns\ValidatesAttributes.php
|
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
|
namespace Illuminate\Validation\Concerns;...trait ValidatesAttributes{... /** * Validate that an attribute is numeric.(验证属性是数字的。) * * @param string $attribute * @param mixed $value * @return bool */ protected function validateNumeric($attribute, $value) { return is_numeric($value); } return false; } elseif ($value instanceof File) { return (string) $value->getPath() != ''; } return true; }...} |
这个就是刚才'required|numeric'的numeric对应执行的方法,不信可以在下面加上
|
1
2
3
4
|
protected function validateMobile($attribute, $value, $parameters) { return preg_match("/^1[34578]{1}\d{9}$/",$value); } |
把刚才的ValidateServiceProvider.php的启动注入注释掉
|
1
2
3
4
5
6
7
8
9
|
public function boot() { //Validator::extend('mobile', function($attribute, $value, $parameters) { //return preg_match("/^1[34578]{1}\d{9}$/",$value); //}); } |
执行还是会验证,不过一般都是在外面注入,写在里面只是测试下。
Laravel validate 500异常 添加手机验证,中文验证与Validator验证的“半个”生命周期的更多相关文章
- Lumen开发:添加手机验证,中文验证与Validator验证的“半个”生命周期
版权声明:本文为博主原创文章,未经博主允许不得转载. 添加手机验证方法可直接看这里:https://www.cnblogs.com/cxscode/p/9609828.html 今天来讲一下,Lume ...
- iOS 添加手机密码、指纹进行安全验证
为APP添加安全验证 1.导入头文件 #import <LocalAuthentication/LocalAuthentication.h> 2.添加手机密码验证 //创建安全验证对象 L ...
- EasyUI表单验证,自定义插件验证,自定义js插件验证,远程验证,常见手机号,中英文,qq等验证规则验证
{ field : 'startPort', title : "起始端口", editor: "text", width : 50, editor: { ...
- Laravel 入口文件解读及生命周期
这里只贴index.php的代码, 深入了解的请访问 https://laravel-china.org/articles/10421/depth-mining-of-laravel-life- ...
- 【干货】Laravel --Validate (表单验证) 使用实例
前言 : Laravel 提供了多种方法来验证应用输入数据.默认情况下,Laravel 的控制器基类使用ValidatesRequests trait,该trait提供了便利的方法通过各种功能强大的验 ...
- jQuery validate 根据 asp.net MVC的验证提取简单快捷的验证方式(jquery.validate.unobtrusive.js)
最近在学习asp.netMVC,发现其中的验证方式书写方便快捷,应用简单,易学好懂. 验证方式基于jQuery的validate 验证方式,也可以说是对jQuery validate的验证方式的扩展, ...
- SpringBoot系列教程web篇之404、500异常页面配置
接着前面几篇web处理请求的博文,本文将说明,当出现异常的场景下,如404请求url不存在,,403无权,500服务器异常时,我们可以如何处理 原文友链: SpringBoot系列教程web篇之404 ...
- laravel拓展validator验证
https://blog.csdn.net/zl20117/article/details/53536520 首先,扩展的收个问题是,我的扩展类应该放在哪儿才好呢? 直接在app目录下,建立一个目录: ...
- C#验证中文
C#验证中文的方式有很多种,下面列举了其中几种可供参考,还有正则表达式的验证这里没有写,后面有机会再补上. 方法一: private bool isChina(string msg) { string ...
随机推荐
- 【原】Spring整合Redis(第一篇)—SDR简述
1.SDR说明 Spring Data Redis(SDR),是SpringFramework提供的一套简化访问Redis的API,是对Jedis的又一层封装. SDR集成了Jedis,JRedis, ...
- HDU 4733 G(x) (2013成都网络赛,递推)
G(x) Time Limit: 2000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- STM32F4 External interrupts
STM32F4 External interrupts Each STM32F4 device has 23 external interrupt or event sources. They are ...
- 打印 Go 结构体(struct)信息:fmt.Printf("%+v", user)
package main import "fmt" // 用户 type User struct { Id int Name string Age int } func main( ...
- 《Go学习笔记 . 雨痕》类型
一.基本类型 清晰完备的预定义基础类型,使得开发跨平台应用时无须过多考虑符合和长度差异. 类型 长度 默认值 说明 bool 1 false byte 1 0 uint8 int, uint 4, ...
- HTML一些标签注意事项
最近在IE10下运行一个以前的做web系统发现了两个小问题: 一.图片上使用"alt"属性来添加一些文字提示信息在IE10下无法正常显示出来 上网查了一下原因:原来是现在一些较新的 ...
- Delphi的命令行编译命令
Borland出品的Delphi,有着闪电般的编译速度,但是在界面控件使用较多.工程项目较大的时候,编译一个工程仍需要一段时间,打开庞大的Delphi IDE,也需要时间.其实,在一个工程开发结束,调 ...
- TStream实现多表提交
TStream实现多表提交 function TynFiredac.SaveDatas(const ATableName, ATableName2: string; ADeltas: TStream; ...
- 关于UIImageView的显示问题——居中显示或者截取图片的中间部分显示
我们都知道在ios中,每一个UIImageView都有他的frame大小,但是如果图片的大小和这个frame的大小不符合的时候会怎么样呢?在默认情况,图片会被压缩或者拉伸以填满整个区域. 通过查看UI ...
- DroidGap
import com.phonegap.DroidGap; import android.app.Activity; import android.os.Bundle; p ...