Laravel 5验证修剪 [英] Laravel 5 Validation Trim
本文介绍了Laravel 5验证修剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Laravel 5的初学者.
I am a beginner in Laravel 5.
如何删除验证器中的空格?我已经阅读了文档,但是没有用于trim的验证器(删除空格).
How can I remove whitespaces in validator?? i have read the documentation but there is no validator for trim(remove whitespaces).
这是我的规则
$rules = [
'name' =>'required',
'email' => 'required|email',
'address' => 'required',
'phones' => 'required'
];
感谢您的回答.
推荐答案
验证者不更改任何输入数据.修剪验证器存在于CodeIgniter中,但对我而言,这不是执行修剪的合适位置.
It's not job for validator to change any input data. Trim validator exists in CodeIgniter, but as to me this isn't right place to perform trim.
您可以使用以下方法自动修剪所有输入:
You can automatically trim all input by using using this:
Input::merge(array_map('trim', Input::all()));
现在完成其余的编码:
$username = Input::get('username'); // it's trimed
// ...
Validator::make(...);
这篇关于Laravel 5验证修剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文