Bob
Bob

Reputation: 169

Respect\Validation - validate string if not empty, otherwise return true

I'm using Respect\Validation for validate fields. Some of my fields are not mandatory, as the phone number, but if they are not empty they must be validated. Following my current code:

v::Phone()->validate($phoneNumber); // it should return true if $phoneNumber is empty

How to do it?

Upvotes: 0

Views: 571

Answers (1)

Don't Panic
Don't Panic

Reputation: 41810

Based on the docs, it looks like it should be:

v::optional(v::Phone())->validate($phoneNumber);

Upvotes: 1

Related Questions