简体   繁体   English

Respect \\ Validation-验证字符串(如果不为空),否则返回true

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

I'm using Respect\\Validation for validate fields. 我正在使用Respect \\ Validation来验证字段。 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? 怎么做?

根据docs ,看起来应该是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM