php - Laravel 4 : Best Practice to Trim Input before Validation -
now, trim each input separately below code:
$username = trim(input::get('username')); $password = trim(input::get('password')); $email = trim(input::get('email')); $validator = validator::make(array('username' => $username, 'password' => $password, 'email' => $email), array('username' => 'required|min:6', 'password' => 'required|min:6', 'email' => 'email'));
is approach trim @ same time with
input::all()
or input::only('username', 'password', 'email')
?
and best practice this?
note: solution won't work if of inputs arrays (such "data[]").
you may try this, trim using 1 line of code before validation:
input::merge(array_map('trim', input::all()));
now rest of coding
$username = input::get('username'); // it's trimed // ... validator::make(...);
if want exclude inputs trimming may use following instead if all()
input::except('password');
or may use
input::only(array('username'));
update: since laravel 5.4.*
inputs trimmed because of new trimstrings
middleware. so, no need worry because middleware executes on every request , handles array inputs well.
How To Validate Email With Pattern Using Jquery In Laravel
ReplyDeleteIt is nice jQuery plugin, which allow to build powerfull validation system for forms and Email. Here we make one function like CheckEmail which was check the email and match with Regular Expression(Pattern)..
For More Info:- How To Validate Email With Pattern Using Jquery In Laravel