本文整理汇总了PHP中Respect\Validation\Validator::float方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::float方法的具体用法?PHP Validator::float怎么用?PHP Validator::float使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::float方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateProduct
function validateProduct(&$product)
{
$invalids = array();
if (empty($product['name']) || !Validation::string()->length(1, 255)->validate($product['name'])) {
array_push($invalids, 'name');
}
if (empty($product['price']) || !Validation::float()->min(0, true)->validate($product['price'])) {
array_push($invalids, 'price');
}
if (empty($product['amount']) || !Validation::int()->min(1, true)->validate($product['amount'])) {
array_push($invalids, 'amount');
}
if (empty($product['categoryId']) || !Validation::int()->max(10, true)->validate($product['categoryId'])) {
array_push($invalids, 'categoryId');
}
return $invalids;
}
示例2: validate
/**
* @PrePersist
* @PreUpdate
*/
public function validate()
{
v::float()->assert($this->amount);
v::numeric("+")->startsWith("+")->assert($this->phone);
v::notEmpty()->assert($this->status);
}
示例3: validateCombo
function validateCombo(&$combo)
{
$invalids = array();
if (empty($combo['name']) || !Validation::string()->length(1, 255)->validate($combo['name'])) {
array_push($invalids, 'name');
}
if (empty($combo['price1']) || !Validation::float()->min(0, true)->validate($combo['price1'])) {
array_push($invalids, 'price1');
}
if (empty($combo['amount1']) || !Validation::int()->min(1, true)->validate($combo['amount1'])) {
array_push($invalids, 'amount1');
}
//check if combos 2, 3 or 4 are given
if (!empty($combo['price2']) || !empty($combo['amount2']) || !empty($combo['price3']) || !empty($combo['amount3']) || !empty($combo['price4']) || !empty($combo['amount4'])) {
if (empty($combo['price2']) || !Validation::float()->min(0, true)->validate($combo['price2'])) {
array_push($invalids, 'price2');
}
if (empty($combo['amount2']) || !Validation::int()->min(1, true)->validate($combo['amount2'])) {
array_push($invalids, 'amount2');
}
} else {
$combo['price2'] = $combo['amount2'] = null;
}
//check if combos 3 or 4 are given
if (!empty($combo['price3']) || !empty($combo['amount3']) || !empty($combo['price4']) || !empty($combo['amount4'])) {
if (empty($combo['price3']) || !Validation::float()->min(0, true)->validate($combo['price3'])) {
array_push($invalids, 'price3');
}
if (empty($combo['amount3']) || !Validation::int()->min(1, true)->validate($combo['amount3'])) {
array_push($invalids, 'amount3');
}
} else {
$combo['price3'] = $combo['amount3'] = null;
}
//check if combo 4 is given
if (!empty($combo['price4']) || !empty($combo['amount4'])) {
if (empty($combo['price4']) || !Validation::float()->min(0, true)->validate($combo['price4'])) {
array_push($invalids, 'price4');
}
if (empty($combo['amount4']) || !Validation::int()->min(1, true)->validate($combo['amount4'])) {
array_push($invalids, 'amount4');
}
} else {
$combo['price4'] = $combo['amount4'] = null;
}
return $invalids;
}
示例4: init
public function init()
{
$this->validator = v::attribute('name', v::string()->notEmpty())->attribute('email', v::email())->attribute('description', v::string()->length(5, 50))->attribute('age', v::callback('is_int')->between(0, 100))->attribute('nick', v::string()->alnum()->noWhitespace())->attribute('creditCard', v::numeric()->creditCard())->attribute('accountBalance', v::float())->attribute('banned', v::bool())->attribute('views', v::callback('is_int')->positive());
}