How to check a field only if it is introduced in Laravel 4?

I am using Laravel 4 in which I have a field email or pincode that you can tell.
Therefore, when using the Laravel validator, I want to check if it is an email or not, only if the value is filled otherwise, it will ignore it.

+3
source share
3 answers

You can use the sometimes rule in the rule list:

$v = Validator::make($data, array(
    'email' => 'sometimes|required|email',
));

http://laravel.com/docs/validation#conditionally-adding-rules

+7
source

email. required , , , , email.

.

...

$validator = Validator::make(
array('pincode' => 'email'),
... other field => rules
);
+1

Laravel will not know about the value before sending your data. So you need to use javascript to check email syntax checking

0
source

All Articles